source: trunk/noc/nagios/status-user/finger.sh @ 1221

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
RevLine 
[1093]1#!/bin/bash
2
[1204]3ulimit -v 10240
4
[1107]5export LINES=1000
6export COLUMNS=80
[1093]7docnagios() {
[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 '
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
[1096]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
[1093]16'
17}
18
[1094]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() {
[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]27read line
[1107]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
[1093]37case "$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
58Available information:
59finger status@sipb-noc -- all services
60finger broken@sipb-noc -- services that are not OKAY
[1097]61finger load@sipb-noc   -- all LOAD services
[1099]62finger scripts-user@sipb-noc-- all scripts user services
[1098]63finger scripts@sipb-noc-- all scripts services
[1095]64finger xvm@sipb-noc    -- only XVM servers
65EOF
[1093]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.