Last change
on this file was
1204,
checked in by quentin, 16 years ago
|
Don't allow users to DoS the finger server on syn
|
-
Property svn:executable set to
*
|
File size:
1.8 KB
|
Line | |
---|
1 | #!/bin/bash |
---|
2 | |
---|
3 | ulimit -v 10240 |
---|
4 | |
---|
5 | export LINES=1000 |
---|
6 | export COLUMNS=80 |
---|
7 | docnagios() { |
---|
8 | echo q | env TERM=ansi /usr/local/nagios/bin/cnagios -b "$@" | sed 's/ |
---|
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 |
---|
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 |
---|
16 | ' |
---|
17 | } |
---|
18 | |
---|
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() { |
---|
24 | gethostgroups | grep "^$1 " | cut -f 2 -d " " | sed 's/,/\n/g' | sort -u | perl -pe 's/\n/|/g' | sed 's/|$//' |
---|
25 | } |
---|
26 | |
---|
27 | read line |
---|
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 |
---|
37 | case "$line" in |
---|
38 | status) |
---|
39 | docnagios |
---|
40 | ;; |
---|
41 | broken) |
---|
42 | docnagios -l w |
---|
43 | ;; |
---|
44 | load) |
---|
45 | docnagios -g /LOAD/ |
---|
46 | ;; |
---|
47 | scripts-user) |
---|
48 | docnagios -g "/$(gethgmembers "scripts-user.*")/" |
---|
49 | ;; |
---|
50 | scripts) |
---|
51 | docnagios -g "/$(gethgmembers "scripts.*")/" |
---|
52 | ;; |
---|
53 | xvm) |
---|
54 | docnagios -g "/$(gethgmembers "xvm.*")/" |
---|
55 | ;; |
---|
56 | *) |
---|
57 | cat <<EOF |
---|
58 | Available information: |
---|
59 | finger status@sipb-noc -- all services |
---|
60 | finger broken@sipb-noc -- services that are not OKAY |
---|
61 | finger load@sipb-noc -- all LOAD services |
---|
62 | finger scripts-user@sipb-noc-- all scripts user services |
---|
63 | finger scripts@sipb-noc-- all scripts services |
---|
64 | finger xvm@sipb-noc -- only XVM servers |
---|
65 | EOF |
---|
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.