source: branches/fc15-dev/noc/nagios/status-user/finger.sh @ 2405

Last change on this file since 2405 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
Line 
1#!/bin/bash
2
3ulimit -v 10240
4
5export LINES=1000
6export COLUMNS=80
7docnagios() {
8        echo q | env TERM=ansi /usr/local/nagios/bin/cnagios -b "$@" | sed 's/
9\[B/\n/g; s/
10/\n/g' | perl -pe '
11s/^.*(?=sipb-nagios)//; # remove garbage at beginning
12s/(.)\\[(\d+)b/$1x($2+1)/ge; # (\d+)b means repeat previous character n times
13s/\\[(\d+)d//g; # absolute go to line; ignored
141 while s/\\[(\d+)G/" "x($1-$-[0]-1)/e; # go to absolute horizontal position
151 while s/\\[\d+;(\d+)H/" "x($1-$-[0]-1)/e; # go to absolute position; line ignored
16'
17}
18
19gethostgroups() {
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
23gethgmembers() {
24    gethostgroups | grep "^$1   " | cut -f 2 -d "       " | sed 's/,/\n/g' | sort -u | perl -pe 's/\n/|/g' | sed 's/|$//'
25}
26
27read line
28line=${line%[:blank:]}
29line=${line%
30}
31
32cols=${line##*-}
33if [ "$cols" -eq "$cols" ] 2>/dev/null; then
34    export COLUMNS="$cols"
35    line=${line%-*}
36fi
37case "$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
58Available information:
59finger status@sipb-noc -- all services
60finger broken@sipb-noc -- services that are not OKAY
61finger load@sipb-noc   -- all LOAD services
62finger scripts-user@sipb-noc-- all scripts user services
63finger scripts@sipb-noc-- all scripts services
64finger xvm@sipb-noc    -- only XVM servers
65EOF
66        ;;
67esac
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.