fix some string marshaling bugs in the Dot Net binding -- Chris Larsen
[rrdtool.git] / bindings / tcl / ifOctets.tcl.in
1 #!/bin/sh
2 # the next line restarts using tclsh -*- tcl -*- \
3 exec tclsh@TCL_VERSION@ "$0" "$@"
4
5 #package require Tnm 3.0
6 package require Rrd @VERSION@
7
8 set rrdfile "[lindex $argv 0]-[lindex $argv 1].rrd"
9
10 # create rrdfile if not yet existent
11 if {[file exists $rrdfile] == 0} {
12     Rrd::create $rrdfile --step 5 \
13             DS:inOctets:COUNTER:10:U:U DS:outOctets:COUNTER:10:U:U \
14             RRA:AVERAGE:0.5:1:12
15 }
16
17 # get an snmp session context
18 set session [Tnm::snmp generator -address [lindex $argv 0]]
19
20 # walk through the ifDescr column to find the right interface
21 $session walk descr IF-MIB!ifDescr {
22
23     # is this the right interface?
24     if {"[Tnm::snmp value $descr 0]" == "[lindex $argv 1]"} {
25
26         # get the instance part of this table row
27         set inst [lindex [Tnm::mib split [Tnm::snmp oid $descr 0]] 1]
28
29         # get the two interface's octet counter values
30         set in [lindex [lindex [$session get IF-MIB!ifInOctets.$inst] 0] 2]
31         set out [lindex [lindex [$session get IF-MIB!ifOutOctets.$inst] 0] 2]
32
33         # write the values to the rrd
34         puts "$in $out"
35         Rrd::update $rrdfile --template inOctets:outOctets N:$in:$out
36
37         Rrd::graph gaga.png --title "gaga" \
38                 DEF:in=$rrdfile:inOctets:AVERAGE \
39                 DEF:out=$rrdfile:outOctets:AVERAGE \
40                 AREA:in#0000FF:inOctets \
41                 LINE2:out#00C000:outOctets
42
43         #puts [Rrd::fetch $rrdfile AVERAGE]
44     }
45 }