Last change
on this file since 1100 was
1100,
checked in by quentin, 15 years ago
|
Remove duplicate hostnames from the regex filter
|
-
Property svn:executable set to
*
|
File size:
1.6 KB
|
Rev | Line | |
---|
[1093] | 1 | #!/bin/bash |
---|
| 2 | |
---|
| 3 | docnagios() { |
---|
[1096] | 4 | echo q | env TERM=ansi LINES=1000 COLUMNS=80 /usr/local/nagios/bin/cnagios -b "$@" | sed 's/ |
---|
[1093] | 5 | \[B/\n/g; s/ |
---|
| 6 | /\n/g' | perl -pe ' |
---|
| 7 | s/^.*(?=sipb-nagios)//; # remove garbage at beginning |
---|
| 8 | s/(.)\\[(\d+)b/$1x($2+1)/ge; # (\d+)b means repeat previous character n times |
---|
| 9 | s/\\[(\d+)d//g; # absolute go to line; ignored |
---|
[1096] | 10 | 1 while s/\\[(\d+)G/" "x($1-$-[0]-1)/e; # go to absolute horizontal position |
---|
| 11 | 1 while s/\\[\d+;(\d+)H/" "x($1-$-[0]-1)/e; # go to absolute position; line ignored |
---|
[1093] | 12 | ' |
---|
| 13 | } |
---|
| 14 | |
---|
[1094] | 15 | gethostgroups() { |
---|
| 16 | cat /etc/nagios3/*.cfg | perl -ne 'print if ( /^(\s*)define hostgroup [\{[]/ ... /[\}\]]/ )' | perl -ne 'm|hostgroup_name\s+(\S+)| and $name = $1; m|members\s+(.+)\s*$| and $members = $1; m|\}| and print "$name\t$members\n"' |
---|
| 17 | } |
---|
| 18 | |
---|
| 19 | gethgmembers() { |
---|
[1100] | 20 | gethostgroups | grep "^$1 " | cut -f 2 -d " " | sed 's/,/\n/g' | sort -u | perl -pe 's/\n/|/g' | sed 's/|$//' |
---|
[1094] | 21 | } |
---|
| 22 | |
---|
[1093] | 23 | read line |
---|
| 24 | case "$line" in |
---|
| 25 | status*) |
---|
| 26 | docnagios |
---|
| 27 | ;; |
---|
| 28 | broken*) |
---|
| 29 | docnagios -l w |
---|
| 30 | ;; |
---|
[1097] | 31 | load*) |
---|
| 32 | docnagios -g /LOAD/ |
---|
| 33 | ;; |
---|
[1099] | 34 | scripts-user*) |
---|
| 35 | docnagios -g "/$(gethgmembers "scripts-user.*")/" |
---|
| 36 | ;; |
---|
[1098] | 37 | scripts*) |
---|
| 38 | docnagios -g "/$(gethgmembers "scripts.*")/" |
---|
| 39 | ;; |
---|
[1094] | 40 | xvm*) |
---|
| 41 | docnagios -g "/$(gethgmembers "xvm.*")/" |
---|
| 42 | ;; |
---|
[1093] | 43 | *) |
---|
[1095] | 44 | cat <<EOF |
---|
| 45 | Available information: |
---|
| 46 | finger status@sipb-noc -- all services |
---|
| 47 | finger broken@sipb-noc -- services that are not OKAY |
---|
[1097] | 48 | finger load@sipb-noc -- all LOAD services |
---|
[1099] | 49 | finger scripts-user@sipb-noc-- all scripts user services |
---|
[1098] | 50 | finger scripts@sipb-noc-- all scripts services |
---|
[1095] | 51 | finger xvm@sipb-noc -- only XVM servers |
---|
| 52 | EOF |
---|
| 53 | |
---|
[1093] | 54 | ;; |
---|
| 55 | esac |
---|
| 56 | #s/\\[\d*[a-zA-Z]//g' |
---|
| 57 | #perl -pe 's/^.*?\[H //s; s/.\[\d+;1H/\n/g; s/^\s+//mg;' |
---|
| 58 | |
---|
| 59 | # s/^\s+$//mg; s/Command: .*//s; s/$/\[0m/' |
---|
Note: See
TracBrowser
for help on using the repository browser.