User Tools

Site Tools


informatique:logiciels:nagios

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
informatique:logiciels:nagios [2020/11/20 15:53] – [Contrôler Nagios en CLI] pteuinformatique:logiciels:nagios [2021/01/15 15:47] (current) – [Contrôler Nagios en CLI] nagios_downtime_w_childs.sh pteu
Line 1741: Line 1741:
  
 Exemples de scripts inspirés de ceux de la doc : Exemples de scripts inspirés de ceux de la doc :
-  * ''nagios_downtime-host-and-childs.sh'' : permet de planifier un DOWNTIME pour un host et tous ces childs. +  * ''nagios_downtime-host-and-childs.sh'' : permet de planifier un DOWNTIME à partir de maintenant pour un ou des hosts et tous ces childs. 
-<code bash>+<code bash nagios_downtime-host-and-childs.sh>
 #!/bin/bash #!/bin/bash
 # This is a sample shell script showing how you can submit the SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME command # This is a sample shell script showing how you can submit the SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME command
Line 1753: Line 1753:
 end=`expr $now + $1` end=`expr $now + $1`
 comment="$2" comment="$2"
 +shift 2
  
-while [ -n "$3" ]; do+while [ -n "$1" ]; do
    /usr/bin/printf "[%lu] SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME;$3;$now;$end;1;0;7200;toto;$comment\n" $now > $commandfile    /usr/bin/printf "[%lu] SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME;$3;$now;$end;1;0;7200;toto;$comment\n" $now > $commandfile
    shift    shift
Line 1760: Line 1761:
 </code> </code>
  
 +  * permet de planifier un downtime pour un host et ses childs à un date donnée
 +<code bash nagios_downtime_w_childs.sh>
 +function usage {
 +        echo "Usage: ${O##*/} <host> <date_debut> (format: \"%Y-%m-%d %H:%M:%S\")> <date_fin> \"<commentaire>\""
 +        echo " format dates: \"%Y-%m-%d %H:%M:%S\""
 +        echo " ex: nagios_downtime_w_childs.sh switch1 \"2021-01-15 07:18:00\" \"2021-01-15 07:48:00\" \"test downtime 30min\""
 +        exit 1
 +        }
 +
 +[ -z "$4" ] && usage
 +
 +now=$(date +%s)
 +commandfile='/var/nagios/rw/nagios.cmd'
 +
 +# affectation et contrôle des inputs
 +naghost=$1
 +debut=$(date -d "$2" +%s 2>/dev/null)
 +[ -z "$debut" ] && { echo "Date début $2 invalide !"; usage; }
 +#[[ "$3" =~ ^[0-9]*$ ]] && fin=`expr $debut + $3` || { echo "ERR: Durée $3 invalide !"; usage; }
 +fin=$(date -d "$3" +%s 2>/dev/null)
 +[ -z "$fin" ] && { echo "Date fin $3 invalide !"; usage; }
 +comment="$4"
 +
 +/usr/bin/printf "[%lu] SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME;$naghost;$debut;$fin;1;0;7200;toto;$comment\n" $now > $commandfile
 +</code>
 =====Annuler des actions en masse===== =====Annuler des actions en masse=====
  
informatique/logiciels/nagios.1605887619.txt.gz · Last modified: 2020/11/20 15:53 by pteu