Skip to main content

Hello the community !

I’ve learned how to use CLAPI commands to make a massive import of hosts, withe following line :

centreon -u uusername] -p ppassword] -i ImportHost.csv

ImportHost.csv is created with the following format :
HOST;ADD;Device;Alias;IP;Template(s);Poller;HostGroup

 

Now, I’d like to remove massively devices from a hostGroup. The CLAPI is given below :
centreon -u nusername] -p ]password] -o HG -a delmember -v "HostGroup;Device"

 

Do you know the way to create a file with the list of devices to remove from the hostGroup, in order to execute the action with a unique command ?

(something like centreon -u eusername] -p mpassword] -i DeviceToRemoveFromTheHostGroup.csv)

Thanks,

Pierre

I don’t think you can do it directly with a file but you can make a script that will do the same thing.

you file should looks like this (1 device per line) :
device1

device2

device3

….

script below :

#!/bin/bash

username=$1
password=$2
hostgroup=$3
file=$4

if >i "x$username" == "x" ]]; then
echo "error : username not found"
echo "Usage : ./<script_name> <username> <password> <hostgroup> <file>"
exit 1
fi

if >i "x$password" == "x" ]]; then
echo "error : password not found"
echo "Usage : ./<script_name> <username> <password> <hostgroup> <file>"
exit 1
fi

if >i "x$hostgroup" == "x" ]]; then
echo "error : hostgroup not found"
echo "Usage : ./<script_name> <username> <password> <hostgroup> <file>"
exit 1
fi

if >i "x$file" == "x" ]]; then
echo "error : file not found"
echo "Usage : ./<script_name> <username> <password> <hostgroup> <file>"
exit 1
fi

while read ligne
do
centreon -u $username -p $password -o HG -a delmember -v "$hostgroup;$line"
done < $file
exit 0

 


Thanks Wisonic, I’m checking your solution and I’ll send you a feedback


Wisonic solution is correct. 

You have to do several commands and script around it as it’s not possible to remove several member from a Hostgroup with a single command. 


I made a typo, it's not

while read ligne

but

while read line

 


Hello,

I’m newer on Centreon, and I really don’t know how to write a script :thinking:

Perhaps can you help me, or indicate where I can find a tutorial on it ?

Thanks,


1) connect to the terminal that hosts your Centreon
2) create a file (I advise you to create a folder where you will put all your Centreon scripts)
mkdir -p /usr/share/centreon/script/ #create folder

vi /usr/share/centreon/script/delete_device_from_hostgroup.sh #create file

3) paste the script in the file

check how to do that : https://staff.washington.edu/rells/R110/
4) make the file executable

chmod 755 /usr/share/centreon/script/delete_device_from_hostgroup.sh
5) run the file

/usr/share/centreon/script/delete_device_from_hostgroup.sh <user> <password> <hostgroup> <file>

(change the words between "<>" by the true values)


Thank you Wisonic, I just applied your code, and it works exactly as I expected !


Reply