Skip to main content
Solved

Hostname configuration

  • January 10, 2023
  • 2 replies
  • 173 views

amarginier

hello

In configuration and Host all my hosts are lowercase, is it possible to rename all to uppercase easily

may be with clapi 

Best answer by christophe.niel-ACT

you are in luck, I developped a script with clapi for that a while ago, use it at your own risk

(I make this kind of script as I don’t like using my login and password in the bash command line)

#!/bin/bash

read -p "Enter Username: " CENTUSER
read -s -p "Enter Password: " CENTPASS
echo
export CENTUSER=$CENTUSER
export CENTPASS=$CENTPASS


IFS=$'\n' my_hosts=( $(centreon -u $CENTUSER -p "$CENTPASS" -o HOST -a show) )
nbhost=${#my_hosts[@]}

for host in "${my_hosts[@]}:1"
do
  HOST=$( echo ${host} | awk -F  ";" '{print $2}' )
  ALIAS=$( echo ${host} | awk -F  ";" '{print $3}' )

  NEWHOST=${HOST^^}
  NEWALIAS=${ALIAS^^}


  echo "$HOST ==> $NEWHOST ; $ALIAS ==> $NEWALIAS"

  #centreon -u $CENTUSER -p "$CENTPASS" -o HOST -a setparam -v "${HOST};alias;${NEWALIAS}"
  #centreon -u $CENTUSER -p "$CENTPASS" -o HOST -a setparam -v "${HOST};name;${NEWHOST}"

done

run it as is, it will show you the new name and alias on the console. 

if you are satisfied with the output, remove the comment on the last 2 lines

it will set the new alias and the hostname in uppercase, using the bash syntax ^^ so PLEASE PARSE THE OUTPUT BEFORE REMOVING COMMENT (I have no idea how it behaves with strange characters)

if you don’t want to change the alias and just the hostname, leave the first comment with NEWALIAS

 

(worked on centreon 19.x and still work on 22.04)

View original
Did this topic help you find an answer to your question?

Forum|alt.badge.img+17

you are in luck, I developped a script with clapi for that a while ago, use it at your own risk

(I make this kind of script as I don’t like using my login and password in the bash command line)

#!/bin/bash

read -p "Enter Username: " CENTUSER
read -s -p "Enter Password: " CENTPASS
echo
export CENTUSER=$CENTUSER
export CENTPASS=$CENTPASS


IFS=$'\n' my_hosts=( $(centreon -u $CENTUSER -p "$CENTPASS" -o HOST -a show) )
nbhost=${#my_hosts[@]}

for host in "${my_hosts[@]}:1"
do
  HOST=$( echo ${host} | awk -F  ";" '{print $2}' )
  ALIAS=$( echo ${host} | awk -F  ";" '{print $3}' )

  NEWHOST=${HOST^^}
  NEWALIAS=${ALIAS^^}


  echo "$HOST ==> $NEWHOST ; $ALIAS ==> $NEWALIAS"

  #centreon -u $CENTUSER -p "$CENTPASS" -o HOST -a setparam -v "${HOST};alias;${NEWALIAS}"
  #centreon -u $CENTUSER -p "$CENTPASS" -o HOST -a setparam -v "${HOST};name;${NEWHOST}"

done

run it as is, it will show you the new name and alias on the console. 

if you are satisfied with the output, remove the comment on the last 2 lines

it will set the new alias and the hostname in uppercase, using the bash syntax ^^ so PLEASE PARSE THE OUTPUT BEFORE REMOVING COMMENT (I have no idea how it behaves with strange characters)

if you don’t want to change the alias and just the hostname, leave the first comment with NEWALIAS

 

(worked on centreon 19.x and still work on 22.04)


amarginier

Many thanks


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings