Last change
on this file since 1221 was
1204,
checked in by quentin, 15 years ago
|
Don't allow users to DoS the finger server on syn
|
-
Property svn:executable set to
*
|
File size:
1.8 KB
|
Rev | Line | |
---|
[1093] | 1 | #!/bin/bash |
---|
| 2 | |
---|
[1204] | 3 | ulimit -v 10240 |
---|
| 4 | |
---|
[1107] | 5 | export LINES=1000 |
---|
| 6 | export COLUMNS=80 |
---|
[1093] | 7 | docnagios() { |
---|
[1107] | 8 | echo q | env TERM=ansi /usr/local/nagios/bin/cnagios -b "$@" | sed 's/ |
---|
[1093] | 9 | \[B/\n/g; s/ |
---|
| 10 | /\n/g' | perl -pe ' |
---|
| 11 | s/^.*(?=sipb-nagios)//; # remove garbage at beginning |
---|
| 12 | s/(.)\\[(\d+)b/$1x($2+1)/ge; # (\d+)b means repeat previous character n times |
---|
| 13 | s/\\[(\d+)d//g; # absolute go to line; ignored |
---|
[1096] | 14 | 1 while s/\\[(\d+)G/" "x($1-$-[0]-1)/e; # go to absolute horizontal position |
---|
| 15 | 1 while s/\\[\d+;(\d+)H/" "x($1-$-[0]-1)/e; # go to absolute position; line ignored |
---|
[1093] | 16 | ' |
---|
| 17 | } |
---|
| 18 | |
---|
[1094] | 19 | gethostgroups() { |
---|
| 20 | 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"' |
---|
| 21 | } |
---|
| 22 | |
---|
| 23 | gethgmembers() { |
---|
[1100] | 24 | gethostgroups | grep "^$1 " | cut -f 2 -d " " | sed 's/,/\n/g' | sort -u | perl -pe 's/\n/|/g' | sed 's/|$//' |
---|
[1094] | 25 | } |
---|
| 26 | |
---|
[1093] | 27 | read line |
---|
[1107] | 28 | line=${line%[:blank:]} |
---|
| 29 | line=${line% |
---|
| 30 | } |
---|
| 31 | |
---|
| 32 | cols=${line##*-} |
---|
| 33 | if [ "$cols" -eq "$cols" ] 2>/dev/null; then |
---|
| 34 | export COLUMNS="$cols" |
---|
| 35 | line=${line%-*} |
---|
| 36 | fi |
---|
[1093] | 37 | case "$line" in |
---|
[1107] | 38 | status) |
---|
[1093] | 39 | docnagios |
---|
| 40 | ;; |
---|
[1107] | 41 | broken) |
---|
[1093] | 42 | docnagios -l w |
---|
| 43 | ;; |
---|
[1107] | 44 | load) |
---|
[1097] | 45 | docnagios -g /LOAD/ |
---|
| 46 | ;; |
---|
[1107] | 47 | scripts-user) |
---|
[1099] | 48 | docnagios -g "/$(gethgmembers "scripts-user.*")/" |
---|
| 49 | ;; |
---|
[1107] | 50 | scripts) |
---|
[1098] | 51 | docnagios -g "/$(gethgmembers "scripts.*")/" |
---|
| 52 | ;; |
---|
[1107] | 53 | xvm) |
---|
[1094] | 54 | docnagios -g "/$(gethgmembers "xvm.*")/" |
---|
| 55 | ;; |
---|
[1093] | 56 | *) |
---|
[1095] | 57 | cat <<EOF |
---|
| 58 | Available information: |
---|
| 59 | finger status@sipb-noc -- all services |
---|
| 60 | finger broken@sipb-noc -- services that are not OKAY |
---|
[1097] | 61 | finger load@sipb-noc -- all LOAD services |
---|
[1099] | 62 | finger scripts-user@sipb-noc-- all scripts user services |
---|
[1098] | 63 | finger scripts@sipb-noc-- all scripts services |
---|
[1095] | 64 | finger xvm@sipb-noc -- only XVM servers |
---|
| 65 | EOF |
---|
[1093] | 66 | ;; |
---|
| 67 | esac |
---|
| 68 | #s/\\[\d*[a-zA-Z]//g' |
---|
| 69 | #perl -pe 's/^.*?\[H //s; s/.\[\d+;1H/\n/g; s/^\s+//mg;' |
---|
| 70 | |
---|
| 71 | # s/^\s+$//mg; s/Command: .*//s; s/$/\[0m/' |
---|
Note: See
TracBrowser
for help on using the repository browser.