1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
jasonralph-> cat clear_semaphores.sh #!/bin/bash ME=`whoami` IPCS_S=`ipcs -s | egrep "0x[0-9a-f]+ [0-9]+" | grep $ME | cut -f2 -d" "` IPCS_M=`ipcs -m | egrep "0x[0-9a-f]+ [0-9]+" | grep $ME | cut -f2 -d" "` IPCS_Q=`ipcs -q | egrep "0x[0-9a-f]+ [0-9]+" | grep $ME | cut -f2 -d" "` for id in $IPCS_M; do ipcrm -m $id; done for id in $IPCS_S; do ipcrm -s $id; done for id in $IPCS_Q; do ipcrm -q $id; done |
Month: August 2014
Parse Nagios status.dat and send daily report
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
#!/bin/bash ################################################################### ################################################################### # # # Script to check Nagios is running and alerts are enabled # # # ################################################################### ################################################################### ECHO="/bin/echo" GREP="/bin/egrep" SED="/bin/sed" PIDOF="/sbin/pidof" #Nagios Parent Host host="nagios" #Logfile Details NAGIOS_LOG="/usr/local/nagios/var" logfile="$NAGIOS_LOG/status.dat" query="enable_notifications" enabled=`ssh $host $GREP $query $logfile | $SED 's/enable_notifications=//g'` PID=`ssh $host "$PIDOF nagios"` #Host Status Details totn_h=`ssh $host $GREP hoststatus $logfile |wc -l` okn_h=`ssh $host $GREP -A50 hoststatus $logfile |$GREP current_state=0 |wc -l` warnn_h=`ssh $host $GREP -A50 hoststatus $logfile |$GREP current_state=1 |wc -l` criticaln_h=`ssh $host $GREP -A50 hoststatus $logfile |$GREP current_state=2 |wc -l` pendingn_h=`ssh $host $GREP -A50 hoststatus $logfile |$GREP current_state=3 |wc -l` notfn_h=`ssh $host $GREP -A50 hoststatus $logfile | $GREP "notifications_enabled=0" |wc -l` #Service Status Details totn_s=`ssh $host $GREP servicestatus $logfile |wc -l` okn_s=`ssh $host $GREP -A50 servicestatus $logfile |$GREP current_state=0 |wc -l` warnn_s=`ssh $host $GREP -A50 servicestatus $logfile |$GREP current_state=1 |wc -l` criticaln_s=`ssh $host $GREP -A50 servicestatus $logfile |$GREP current_state=2 |wc -l` unknownn_s=`ssh $host $GREP -A50 servicestatus $logfile |$GREP current_state=3 |wc -l` notfn_s=`ssh $host $GREP -A50 servicestatus $logfile | $GREP "notifications_enabled=0" |wc -l` #Critical Alerts crit_service_checks=`ssh $host $GREP -B15 current_state=2 $logfile |$GREP -iE "(host_name|service_description|hoststatus|servicestatus)" | $SED '/servicestatus/d' | $SED '$!N;s/\n/ /' | $SED '/hoststatus/d' | $SED 's/host_name=//g' | $SED 's/service_description=//g'` warn_service_checks=`ssh $host $GREP -B15 current_state=1 $logfile |$GREP -iE "(host_name|service_description|hoststatus|servicestatus)" | $SED '/servicestatus/d' | $SED '$!N;s/\n/ /' | $SED '/hoststatus/d' | $SED 's/host_name=//g' | $SED 's/service_description=//g'` crit_host_checks=`ssh $host $GREP -A50 hoststatus $logfile | $GREP -iE "(host_name|current_state)" | $GREP -B1 current_state=2 | $GREP host_name | $SED 's/host_name=//g'` warn_host_checks=`ssh $host $GREP -A50 hoststatus $logfile | $GREP -iE "(host_name|current_state)" | $GREP -B1 current_state=1 | $GREP host_name | $SED 's/host_name=//g'` #Disabled Alerts notf_service_disabled=`ssh $host $GREP -B45 notifications_enabled=0 $logfile |$GREP -iE "(host_name|service_description|hoststatus|servicestatus)" | $SED '/servicestatus/d' | $SED '$!N;s/\n/ /' | $SED '/hoststatus/d' | $SED 's/host_name=//g' | $SED 's/service_description=//g'` notf_host_disabled=`ssh $host $GREP -A50 hoststatus $logfile | $GREP -iE "(host_name|notifications_enabled)" | $GREP -B1 notifications_enabled=0 | $GREP host_name | $SED 's/host_name=//g'` echo " " echo " #######################################" echo " Checking Nagios Status" echo " #######################################" echo " " if [[ -n $PID ]]; then echo "" echo "nagios-------------------------------------------[running]" else echo "" echo "nagios-------------------------------------------[*missing*!Please.resolve]" fi if [ $enabled = 1 ]; then echo "" echo "nagios alerts------------------------------------[Enabled]" elif [ $enabled = 0 ]; then echo "" echo "nagios alerts------------------------------------[*Disabled*!Please.resolve]" fi echo "" echo "Host Status Totals" echo "TOTAL:$totn_h OK:$okn_h WARN:$warnn_h CRITICAL:$criticaln_h PENDING:$pendingn_h" echo "Number of Hosts Silenced: $notfn_h" echo "" echo "Service Status Totals" echo "TOTAL:$totn_s OK:$okn_s WARN:$warnn_s CRITICAL:$criticaln_s UNKNOWN:$unknownn_s" echo "Number of Services Silenced: $notfn_s" if [ $criticaln_h != 0 ]; then echo "" echo "CRITICAL HOST ALERTS:" echo "${crit_host_checks}" fi if [ $warnn_h != 0 ]; then echo "" echo "WARNING HOST ALERTS:" echo "${warn_host_checks}" fi if [ $criticaln_s != 0 ]; then echo "" echo "CRITICAL SERVICES ALERTS:" echo "${crit_service_checks}" fi if [ $warnn_s != 0 ]; then echo "" echo "WARNING SERVICES ALERTS:" echo "${warn_service_checks}" fi if [ $notfn_h != 0 ]; then echo "" echo "HOST ALERTS SILENCED:" echo "${notf_host_disabled}" fi if [ $notfn_s != 0 ]; then echo "" echo "SERVICES ALERTS SILENCED:" echo "${notf_service_disabled}" fi |