source: branches/fc11-dev/noc/nagios/status-user/finger.sh @ 1148

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