Outils pour utilisateurs

Outils du site


Writing /app/www/public/data/meta/centreon/scripts-linux.meta failed
centreon:scripts-linux

Ceci est une ancienne révision du document !


check_A335_backup

#!/bin/bash
##########################################################################################
# Ajout de la ligne de commande pour nrpe dans: /etc/nagios/nrpe.d/check_A335_backup.cfg #
# command[check_A335_backup]=/usr/lib/nagios/plugins/check_A335_backup.sh                #
##########################################################################################
# Deplacement vers le dossier de recherche
cd /mariadb/backup/log/

# Recherche du fichier le + récent
VAR1=$(ls -t | head -n1)

# Recherche du mot pour OK
VAR4=$(grep 'completed OK!' $VAR1)

# Check fichier plus de 1 jour
if [[ $(find "$VAR1" -mtime +1 -print) ]]; then
echo "Log du jour absent"
fi

#Vérif si retour recherche vide
if [[ -z  $VAR4  ]]; then
echo "Backup KO"
fi

# Si fichier OK et backup OK alors OK
if [ -n "$VAR4" ] ; then
echo "Backup et fichier log OK"
exit 0
fi

# Envois du resultat à Centreon
while read line; do echo $line; done
exit 2
######################################
# Rendre le fichier executable       #
# chmod +x check_A335_backup.sh      #
# Pensez à redémarre le service      #
# service nagios-nrpe-server restart #
######################################

check_by_ssh_erreurs_badgeuses.sh

#!/bin/bash
#set -x
HOST=$1

COMMAND=$(ssh -t -i /usr/lib64/nagios/plugins/.ssh/id_rsa_badg opteama@$HOST '{ sleep 10; echo "i tr"; sleep 10; } | axsh | grep "TO SEND"' | cut -c 15-15)
#echo $COMMAND

OUT=$?
    if [ $OUT -eq 1 ]
    then
        echo "Timeout"
        echo $COMMAND
        exit 1
    elif [ $OUT -ne 0 ]
    then
        echo "Unknown ERROR"
        echo $COMMAND
        exit 3
    else
    #echo "ERREURS BADGEUSE"
        RESULTAT=`echo $COMMAND`
        #echo $RESULTAT
        if [ -z $RESULTAT ]
        then echo "VALEUR DE SORTIE DE COMMANDE INEXISTANTE"
        exit 3
        fi
        if [ $RESULTAT -ne 0 ]
            then echo "ERREURS BADGEUSE (TO SEND different de zero): KO"
                sleep 60
                RESULTAT=`echo $COMMAND`
        fi
                if [ $RESULTAT -ne 0 ]
                then echo "ERREURS BADGEUSE (TO SEND different de zero): KO"
        exit 2
        fi
        echo "PAS D'ERREURS sur la BADGEUSE : OK"
        exit 0
    fi

Check_Certfif_asa

#!/bin/bash

#set -x

#Adresse IP en parametre
HOSTNAME=$1

#nom utilisateur d'un profil de gestion des ASA
USERNAME=SARANCIDBck01

#mot de passe du profil de gestion des ASA
PASSWORD=2k3zX4bV9i4hNaHl

MONTH=(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)

#date du jour
NOW=`date +%Y%m%d`

#variable stockant le niveau d'alerte Centreon ( 0: rien , 1: Warning, 2: Critical)
sortie=0


#convertir le mois de l'annee en lettre à chiffre
#Le parametre à passer doit etre de la forme de la liste MONTH (ex: Jan)
mois_chiffre() {

        local i=0
        local len=${#MONTH[@]}
        while [ $i -lt $len ];
        do
                if [[ "$1" == "${MONTH[$i]}" ]]
                then
                        let i++
                        echo "$i"
                        break
                fi
                let i++

        done
}

#verifie l'etat du status
#mettre en parametre le status (ex: "Available")
check_status() {

        stat=`echo $1 | cut -c 1-9`
        if [[ "$stat" != "Available" ]]
        then
                sortie=2

        fi
}

#permet de creer et de renvoyer la variable date du certificat
#mettre les parametres dans l'ordre suivant : year month(lettre) day
create_cert_date() {
        local mois=$(mois_chiffre $2)
        edate=$(date -d $1-$mois-$3 +"%Y%m%d")
        echo $edate
}

#renvoie le delta en jours entre deux dates
#les parametres doivent etre : date_certif date_du_jour
compare_date() {

        let DIFF=($(date +%s -d $1) - $(date +%s -d $2))/86400
        echo $DIFF
}



#section connexion à l'ASA et suite de commandes pour recuperer les certificats des ASA
sshpass -p $PASSWORD ssh -q -o StrictHostKeyChecking=no $USERNAME@$HOSTNAME << 'EOF' | tee "/usr/lib64/nagios/plugins/cisco_asa_show_crypto/output$HOSTNAME.txt" &> /dev/null
enable
2k3zX4bV9i4hNaHl
conf t
pager 0
end
show crypto ca certificates
exit
EOF


while read line; do
        #echo $line
        eval ARRAY=(`echo $line`)
        #echo ${ARRAY[0]}



        #Trustpoints
        if [[ ${ARRAY[0]} == "Associated" ]]
        then
                assos=${ARRAY[2]}
                #CRITICAL : date du certificat inferieur a 15 jours
                if [[ "$delta_date" -lt 15 ]]
                then
                        echo "CRITICAL $stat $delta_date $assos"
                        sortie=2

                #WARNING: date du certificat inferieur a 30 jours
                elif [[ "$delta_date" -lt 30 ]]
                then
                        echo "WARNING $stat $delta_date $assos"

                        if [[ "$sortie" -ne 2 ]]
                        then
                                sortie=3
                        fi
                fi

        fi


        #Status
        if [[ ${ARRAY[0]} == "Status:" ]]
        then
                check_status ${ARRAY[1]} $assos
        fi

        #End Date
        if [[ ${ARRAY[0]} == "end" ]]
        then
                end_jour=`echo ${ARRAY[5]} | cut -c 1-2`
                end_mois=`echo ${ARRAY[4]} | cut -c 1-3`
                end_annee=`echo ${ARRAY[6]} | cut -c 1-4`
                end_date=`create_cert_date $end_annee $end_mois $end_jour`
                delta_date=`compare_date $end_date $NOW`
                #echo "Jours restant avant expiration du certificat : $delta_date"
        fi

done <<< "$(grep -e ^"CA Certificate" -e  ^"Certificate" -e "end   date:" -e "Associated" -e "Status:" /usr/lib64/nagios/plugins/cisco_asa_show_crypto/output$HOSTNAME.txt)"

rm -f /usr/lib64/nagios/plugins/cisco_asa_show_crypto/output$HOSTNAME.txt

#Les certificats sont bons ou il n'y en a pas, on renvoie un output pour Centreon
if [[ $sortie -eq 0 ]]
then
        echo "Certificat(s) OK"
fi


exit $sortie

check_dispo_sla.sh

#!/bin/bash

#suppress error outputs


#try to read vars from file, for windows and tests purpose
if [ -f ./centreon_conf_local.bash ] ; then
    . ./centreon_conf_local.bash
fi

#set default JQ value should be OK on linux if jq is installed
JQ=${JQ:-"jq"}

#debug defincition for execution traces
CENTREON_DEBUG=${CENTREON_DEBUG:-0}

#regexp used for host
CENTREON_HOST_REGEXP=${3:-P-A389-CENS}
CENTREON_HOST_REGEXP=${CENTREON_HOST_REGEXP// /%20}
#regexp used for service
CENTREON_SVC_REGEXP=${4:-CANADA}
CENTREON_SVC_REGEXP=${CENTREON_SVC_REGEXP// /%20}
#centreon url
CENTREON_URL="${5:-https://p-a389-vipp-001.mycorp.corp}"

CENTREON_LOGIN=${1:-userapi_1}
CENTREON_PASSWORD=${2:-Userapi1}

#query centreon token
TOKEN_QUERY_DATA="{\"security\": {\"credentials\": {\"login\": \"$CENTREON_LOGIN\",\"password\": \"$CENTREON_PASSWORD\""
CENTREON_TOKEN=`curl -s -k -X POST -d "$TOKEN_QUERY_DATA" -H "Content-Type: application/json" -X POST $CENTREON_URL/centreon/api/beta/login |  $JQ -s '.[0].security.token' | tr -d \" | sed -e "s/[\"\r]//g"  `

#query used to request sstates
CENTREON_QUERY="\{\"\$and\":\[\{\"service.description\":\{\"\$lk\":\"%$CENTREON_SVC_REGEXP%\"\}\},\{\"host.name\":\{\"\$lk\":\"%$CENTREON_HOST_REGEXP%\"\\\]\"

#function to request data, was more complex at the beginning
centreon_request() {
    # warning at the limit, no High availability with more than 50 instance
    curl -s -k -H "X-AUTH-TOKEN: ${CENTREON_TOKEN}" -H "Content-Type: application/json" -X GET "${CENTREON_URL}/centreon/api/beta/monitoring/services?search=$1&limit=50"
}

#print values used for execution
if [ "$CENTREON_DEBUG" == "1" ]; then
    echo JQ: $JQ
    echo centreon_query: $CENTREON_QUERY
    echo centreon_token: $CENTREON_TOKEN
else
    exec 2>/dev/null
fi


#print query
if [ "$CENTREON_DEBUG" == "1" ]; then
    echo request for $CENTREON_QUERY
fi

# request data
state=`centreon_request ${CENTREON_QUERY}`

#show status codes
if [ "$CENTREON_DEBUG" == "1" ]; then
    echo Results
    echo $state | $JQ  -r ".result | .[].status.code "
fi


# use a service group for that
# compute result which is addition of all status code
# result=`echo $state | $JQ  -r ".result | .[].status.code" | $JQ -s 'add' | tr -d \" | sed -e 's/[\r ]//g'`

# compute result which is mulitplication of all status code
values=`echo $state | $JQ  -r ".result | .[].status.code" | tr -d \" | sed -e 's/\r//g' `
result=1
for i in $values; do
    # echo "result * i : $r * $i"
    result=$((result*i))
    # echo ">> $r"
done

# result=`echo $state | $JQ  -r ".result | .[].status.code" | $JQ -s 'add' | tr -d \" | sed -e 's/[\r ]//g'`

if [[ "$result" == "" ]] ; then
    AGGREGATION_OUPUT=3
    comment="Unknown: Probe Not runned properly"
elif [[ $result == 0 ]] ; then
    AGGREGATION_OUPUT=0
    comment="OK: Nominal State"
else
    AGGREGATION_OUPUT=2
    comment="Critical: Non Nominal State"
fi

if [ "$CENTREON_DEBUG" == "1" ]; then
    echo AGGREGATION_OUPUT: $AGGREGATION_OUPUT
fi

echo $comment"|"
centreon_details=`echo $state | $JQ  -cr ".result | map( {host:.host.name, service:.description, status:.status.name,} ) " | sed -e "s/[}],/},\n/g"`
for detail in "${centreon_details[@]}" ; do
    echo "$detail"
done

exit $AGGREGATION_OUPUT

check_file_age

#! /bin/sh
#Si un fichier .runnning est présent depuis plus de 4h, on alerte
for f in `ls /var/BA/rsync_script/*running 2>/dev/null`
do
        FILECHANGE=`stat --printf=%Y $f`
        CURRENTDATE=`date +%s`
        FILEAGE=$((CURRENTDATE-FILECHANGE))
        if [ $FILEAGE -gt 28800 ]
        then
                echo "CRITICAL - fichier de lock $f présent depuis plus de 2 jours !!!"
                exit 2
        elif [ $FILEAGE -gt 14400 ]
        then
                echo "WARNING - fichier de lock $f présent depuis plus d'une journee"
                exit 1
        fi
done
echo "OK - Rsync OK"
exit 0

check_gile_exist

#! /bin/bash
#
# Author : Diego Martin Gardella [dgardella@gmail.com]
# Desc : Plugin to verify if a file exists
#
#

PROGNAME=`basename $0`
PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`

. $PROGPATH/utils.sh

if [ "$1" = "" ]
then
	echo -e " Use : $PROGNAME <file_name> -- Ex : $PROGNAME /etc/hosts \n "
	exit $STATE_UNKNOWN
fi


if [ -f $1 ]
then
	echo "OK - $1 : EXISTS :: `head -3 $1`" # shows the first three lines of the file
	exit $STATE_OK
else
	echo "CRITICAL : $1 Does NOT exists "
	exit $STATE_CRITICAL
fi

check_gateway_lora

#!/bin/bash
# Vous pouvez decommanter la ligne ci-dessous si vous voulez voir le deroulement du script (debug)
set -x

# On definit les variables

# curl
CURL="/usr/bin/curl"

# La variable que l'on entre en fin de commande dans centreon (nom de la gateway)
HOST=$1

# La variable si dessous est un renouvellement du token a chaque check
TOKEN=`$CURL -s -k -X POST -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: application/json' -d 'grant_type=client_credentials&client_id=tpe-api/ml-operations@stelia-aerospace.com&client_secret=PASS=12hours'  https://lorawan.opteama.stelia.aero/thingpark/dx/admin/latest/api/oauth/token  | grep -oE '"access_token":.*' | awk '{ split($1,a,/"/); print a[4] }'`

# La variable si dessous recupere le ref de la gateway
REF=`$CURL -s -k -X GET -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer '$TOKEN'' https://lorawan.opteama.stelia.aero/thingpark/dx/core/latest/api/baseStations | egrep -o '.*:"'$HOST'"' | awk -F '"' '{print $(NF-13)}'`

# La variable si dessous donne les resultats de l'etat
RESULT=`$CURL -s -k -X GET -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer '$TOKEN'' https://lorawan.opteama.stelia.aero/thingpark/dx/core/latest/api/baseStations/$REF | json_pp -json_opt pretty,canonical | egrep -o '"administrationState" : .*|"connectionState" : .*|"healthState" : .*' | tr -d '\n' | cut -d '"' -f4,8,12`

# Alertes suivant les retour
# Details 'etat adin, etat connexion, etat status'
# Critique = 'ACTIVE"DISC"ACTIVE'
# Warning = 'ACTIVE"NEVERCNX"ACTIVE'
# OK = 'ACTIVE"CNX"ACTIVE'
# autre = 'Unknown response from plugin'

# Si critique
if [[ $RESULT = 'ACTIVE"DISC"ACTIVE' ]]
then
echo "KO Gateway is Critical"
exit 2
fi

# Si warning
if [[ $RESULT = 'ACTIVE"NEVERCNX"ACTIVE' ]]
then
echo "KO Gateway is Warning"
exit 3
fi

check_netapp_lun_size

#! /bin/bash
# Desc : Plugin to verify LUN size on NETAPP
# admin:C1sc0123
# To get lun's uuid:
# curl -s -k -u admin:C1sc0123 -X GET 'https://P-NTAP-CLU-010.infra.aerolia.corp/api/storage/luns?status.state=online' -H 'accept: application/hal+json' | grep -oE '"uuid":.*|"name":.*'

# Decommentez la ligne ci-dessous pour debug
set -x

# Variables
HOST=$1
USER=$2
PASS=$3
LUN=$4
ALERT=$5
HAUT=$6

# check si toutes les variables sont la
if [[ $# -ne 6 ]]
then echo "Il manque des variables"
exit 2
fi

# Commande pour recuperer le total/used de la LUN via son UUID
RESULT=$(curl -k -s -u $USER:$PASS -X GET https://"$HOST"/api/storage/luns/"$LUN"?fields=** -H 'accept: application/hal+json' | grep -oE '"size":.*|"used":.*' | tr -d '\n' | awk '{$2=$2/(1024^3); $3=$3/(1024^3);print "USED:",$3,"GB","_ TOTAL:",$2,"GB"}')

# On coupe le resultat pour garder le used
TOTAL=`echo $RESULT | awk '{split($2,a,"."); print a[1]}'`

# On coupe le resultat pour garder le total multiplie par la variable pourcentage mise sans la commande pour definir les seuils d'alertes
WARN=`echo $RESULT | awk '{split($6,a,"."); print a[1]*'$ALERT'/100}' | cut -d "." -f1`
CRIT=`echo $RESULT | awk '{split($6,a,"."); print a[1]*'$HAUT'/100}' | cut -d "." -f1`

# Si critique
if [[ $TOTAL -gt "$CRIT" ]]
then
echo "LUN Usage is CRITICAL: $RESULT"
exit 2
fi

# Si warning
if  [[ $TOTAL -gt "$WARN" ]]
then
echo "LUN Usage is Warning: $RESULT"
exit 1


# Si OK
else
echo "LUN Usage is OK: $RESULT"
fi

check_netapp_volume

#Faire un service 

#/opt/netapp-api-exporter/netapp-api-exporter_linux_amd64 -c /opt/netapp-api-exporter/netapp-filers.yaml -l 127.0.0.1 -v 5m  --no-aggregate --no-system
# Desc : Plugin to verify volume size on NETAPP

# Pour lister les volumes sur le Vfilers
# curl -s http://127.0.0.1:9108/metrics | grep 'P-NTAP-CLU-001' | grep -oE 'netapp_volume_total_bytes.*' | grep -oE '.*p-vf-airbus-02.*' | grep -oE 'volume=.*'| cut -d '"' -f2

# Decommentez la ligne ci-dessous pour debug
# set -x

# Variables
CLU=$1
VFL=$2
VOL=$3
WARN=$4
CRIT=$5

RESULT=$(curl -s http://127.0.0.1:9108/metrics | grep -oE 'netapp_volume_used_percentage.*' |  grep '.*'$CLU'.*' | grep -oE '.*'$VFL'.*' | grep -oE ''$VOL'.*' | awk '{ split($0,a,/"/); print "Volume", a[1],"Used",$2,"%" }')
TOTAL=$(curl -s http://127.0.0.1:9108/metrics | grep -oE 'netapp_volume_total_bytes.*' | grep '.*'$CLU'.*' | grep -oE '.*'$VFL'.*' | grep -oE ''$VOL'.*' | awk '{ split($0,a,/"/); print "Volume", a[1],"Used",$2,"%" }' | awk '{ split($4,a,/e/); print a[1]*100,"GB"}')
PRCT=`echo "$RESULT" | awk '{print $4}'`

# Si critique
if [[ $PRCT -gt "$CRIT" ]]
then
echo "Volume Usage is CRITICAL: $RESULT de $TOTAL"
exit 2

# Si warning
elif  [[ $PRCT -gt "$WARN" ]]
then
echo "Volume Usage is Warning: $RESULT de $TOTAL"
exit 1

# Si pas de résultat unknown
elif  [[ -z $PRCT  ]]
then
echo "No response from plugin"
exit 3

# Si OK
else
echo "Volume Usage is OK: $RESULT de $TOTAL"
fi
centreon/scripts-linux.1688559107.txt.gz · Dernière modification : 2024/12/27 06:28 (modification externe)