Créons une nouvelle commande Clapi
21/11/17 08:47 Classé dans: Techniques
![upgrade-centreon2602015-04-22_09-26-55_PM](upgrade-centreon2602015-04-22_09-26-55_pm.png)
Celui-ci utilisera deux commandes clapi :
centreon -u user -p password -o INSTANCE -a SHOW
et
centreon -u user -p password -o INSTANCE -a GETHOSTS -v poller>
Ce script fonctionne avec Centreon-web 2.8.15. Attention, celui-ci ne gère pas les erreurs d'identification. Voici la syntaxe :
./get_instances.sh -h
Usage: get_instances.sh -u-p -o
This program show instance associated with the requested host.
-u User Centreon.
-p Password Centreon
-o name host
-h help
Exemple :
pi@raspberrypi:~ $ ./get_instances.sh -u admin -p password -o vmtechcentreon
vmtechcentreon is associated to Central
Et voici le code
#!/bin/bash
# get_instances.sh
# version 1.00
# date 20/11/2017
# Usage info
show_help() {
cat << EOF
Usage: ${0##*/} -u-p -o
This program show instance associated with the requested host.
-u User Centreon.
-p Password Centreon
-o name host
-h help
EOF
exit 2
}
while getopts 'u:p:ho:' OPTION
do
case $OPTION in
u)
USER_CENTREON="$OPTARG"
;;
p)
PWD_CENTREON="$OPTARG"
;;
o) NAME_HOST="$OPTARG"
;;
?|h) show_help
;;
esac
done
shift $(($OPTIND - 1))
# Check for missing parameters
if [ -z "${USER_CENTREON}" ] || [ -z "${PWD_CENTREON}" ] || [ -z "${NAME_HOST}" ]; then
echo "Missing parameters!"
show_help
fi
TAIL=/usr/bin/tail
CLAPI=/usr/share/centreon/bin/centreon
# read instance
function read_instance ()
{
$CLAPI -u $USER_CENTREON -p $PWD_CENTREON -o INSTANCE -a SHOW | $TAIL -n+2 |
#lecture param
while read line
do
NAME_INSTANCE=`echo $line | cut -d ";" -f2 `
read_gethost $NAME_INSTANCE
done
}
# read getshost
function read_gethost ()
{
$CLAPI -u $USER_CENTREON -p $PWD_CENTREON -o INSTANCE -a GETHOSTS -v $1 | $TAIL -n+2 |
#lecture param
while read line
do
NAME=`echo $line | cut -d";" -f2 `
if [ "$NAME_HOST" == "$NAME" ]; then
echo $NAME_HOST" is associated to "$1
exit 1
fi
done
}
read_instance
blog comments powered by Disqus