Dzahn has submitted this change and it was merged. Change subject: icinga: add script to schedule host downtimes ......................................................................
icinga: add script to schedule host downtimes Adds a script to schedule icinga host downtimes from the commandline. Bug:T79842 Change-Id: If82d9402edbc9e88c0f6a35ac795e37e0cedf0ce --- A modules/icinga/files/schedule-downtime M modules/icinga/manifests/init.pp 2 files changed, 59 insertions(+), 0 deletions(-) Approvals: jenkins-bot: Verified Dzahn: Looks good to me, approved diff --git a/modules/icinga/files/schedule-downtime b/modules/icinga/files/schedule-downtime new file mode 100755 index 0000000..89fc7f5 --- /dev/null +++ b/modules/icinga/files/schedule-downtime @@ -0,0 +1,49 @@ +#!/bin/bash +# schedule a downtime on icinga +# dzahn 20150513 +# +# usage: ./schedule_downtime -h <hostname> -d <duration> -r <reason> +# example: ./schedule_downtime -h mw1021 -d 7200 -r "something happened" +# +# -h <hostname> should be the (short) name of a host as shown in the Icinga UI +# -d <duration> how long should the downtime last, in seconds (2 hrs = 7200) +# -r <reason> a string with the reason for the downtime + +commandfile="/var/lib/nagios/rw/nagios.cmd" +logfile="/var/log/icinga/icinga.log" +user="marvin-bot" # because it's a _down_time bot, get it?:p + +while getopts "h:d:r:" opts; do +case $opts in + h) + hostname=$OPTARG + ;; + d) + duration=$OPTARG + ;; + r) + reason=$OPTARG + ;; + \?) + echo "invalid option: '$OPTARG'" + exit 1 + ;; + :) + echo "option '$OPTARG' requires an argument" + exit 1 + ;; +esac +done + +if [ -z $hostname ] || [ -z $duration ] || [ -z $reason ]; then + echo "usage: $0 -h <hostname> -d <duration> -r <reason>" + exit +fi + +start_time=$(date +%s) # now +end_time=$(( $start_time + $duration )) + +printf "[%lu] SCHEDULE_HOST_DOWNTIME;${hostname};${start_time};${end_time};1;0;${duration};${user};${reason}\n" $(date +%s) > $commandfile + +tail -f $logfile | grep -m2 $hostname + diff --git a/modules/icinga/manifests/init.pp b/modules/icinga/manifests/init.pp index 1ad4ad2..ab9e60e 100644 --- a/modules/icinga/manifests/init.pp +++ b/modules/icinga/manifests/init.pp @@ -162,4 +162,14 @@ check_command => 'check_icinga_config', normal_check_interval => 10, } + + # script to schedule host downtimes + file { '/usr/local/bin/schedule-downtime': + ensure => present, + source => 'puppet:///modules/icinga/schedule-downtime', + owner => 'root', + group => 'root', + mode => '0550', + } + } -- To view, visit https://gerrit.wikimedia.org/r/210824 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: If82d9402edbc9e88c0f6a35ac795e37e0cedf0ce Gerrit-PatchSet: 3 Gerrit-Project: operations/puppet Gerrit-Branch: production Gerrit-Owner: Dzahn <dz...@wikimedia.org> Gerrit-Reviewer: Dzahn <dz...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits