File: bogart

package info (click to toggle)
scotty 2.1.9-1
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 9,984 kB
  • ctags: 4,313
  • sloc: ansic: 35,946; sh: 12,591; tcl: 8,122; yacc: 2,442; makefile: 898; lex: 370
file content (138 lines) | stat: -rwxr-xr-x 3,025 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#! /usr/local/bin/scotty -nf
## -*- tcl -*-
##
## Copyright (c) 1995
##
## J. Schoenwaelder
## TU Braunschweig, Germany
## Institute for Operating Systems and Computer Networks
##
## Permission to use, copy, modify, and distribute this
## software and its documentation for any purpose and without
## fee is hereby granted, provided that the above copyright
## notice appear in all copies.  The University of Braunschweig
## makes no representations about the suitability of this
## software for any purpose.  It is provided "as is" without
## express or implied warranty.
##

proc BogartError {msg} {
    syslog info "bogart: $msg"
}

proc BogartResult {query} {
    set f [open /usr/tmp/bogart.sql a+]
    puts $f "$query\n\\g"
    close $f
}

proc BogartSubmit {url} {
    if {[catch {http put $url /usr/tmp/bogart.sql} msg]} {
	BogartError $msg
	return
    }
    catch {exec rm -f /usr/tmp/bogart.sql}
}

proc BogartGetIp {host} {
    if {[regexp "^\[0-9\]+\.\[0-9\]+\.\[0-9\]+\.\[0-9\]+$" $host]} {
	return $host
    }
    set code [catch {netdb hosts address $host} ip]
    if $code {
	set ip [dns a $host]
    }
    return $ip
}

##
## SNMP monitoring scripts.
##

proc SnmpScalarsProc {s group} {

    set list [SNMP_Scalars $s $group value]

    set fields ""
    set values ""
    foreach name $list {
	lappend fields [lindex [split $name .] 0]
	set syntax [mib syntax $name]
	set tc [mib tc $name]
	if {$tc != ""} {
	    set syntax [lindex $tc 1]
	}
	switch $syntax {
	    TimeTicks -
	    INTEGER {
		lappend values [mib scan $name $value($name)]
	    }
	    "OCTET STRING" {
		lappend values '$value($name)'
	    }
	    "OBJECT IDENTIFIER" {
		if {[catch {mib oid $value($name)} oid]} {
		    lappend values '$value($name)'
		} else {
		    lappend values '$oid'
		}
	    }
	    default {
		lappend values $value($name)
	    }
	}
    }

    set query "insert into $group (Target,TimeStamp,[join $fields ,]) \
	    values ('[SNMPGetIP $s]',[clock seconds],[join $values ,])"
    BogartResult $query
}

proc MonitorSnmpScalars {group alias interval} {
    set s [snmp session -alias $alias]
    job create "SnmpScalarsProc $s $group" [expr $interval * 1000]
}

##
## Monitor the network time protocol information.
##

proc NtpProc {ip} {
    if {[catch {ntp $ip values} msg]} {
	BogartError "$ip: $msg"
	return
    }
}

proc MonitorNtp {host interval} {
    set ip [BogartGetIp $host]
    job create "NtpProc $ip" [expr $interval * 1000]
}

##
## Monitor round trip time via ICMP echo messages.
##

proc IcmpRttProc {ip} {
    set rtt [lindex [lindex [icmp echo $ip] 0] 1]
    set query "insert into IcmpRtt (Target,TimeStamp,rtt) \
	    values ('$ip',[clock seconds],$rtt)"
    BogartResult $query
}

proc MonitorIcmpRtt {host interval} {
    set ip [BogartGetIp $host]
    job create "IcmpRttProc $ip" [expr $interval * 1000]
}

##
## And here is the main program. Simply source all configuration 
## files and start monitoring. That's it.
##

foreach f $argv {
    if {[file readable $f]} {
	source $f
    }
}