The unified diff between revisions [0639490d..] and [19d4693b..] is displayed below. It can also be downloaded as a raw diff.

#
#
# patch "plugins/basic_snmp.py"
#  from [b31e67918315f0373741bd567fa881f5f137b086]
#    to [70769aabb99d393217f8760c13214b38696921ed]
#
# patch "plugins/cisco_ios.py"
#  from [da39a3ee5e6b4b0d3255bfef95601890afd80709]
#    to [435cb5aa7252bf973200b392a7465de7321766a8]
#
# patch "tables/ethernet_forwarding.csv"
#  from [91a6649f3ceeea0276a7d8a73639a28943af92d3]
#    to [b7e1c7e10c68fdc6d544255a2d13ea7460c859cc]
#
# patch "yowie.py"
#  from [ef2df1fc34094e09a0c1cb771c03dbd744a8c933]
#    to [3e57b46eee9446cfb98f258c312df9df5a5cb8a6]
#
============================================================
--- plugins/basic_snmp.py	b31e67918315f0373741bd567fa881f5f137b086
+++ plugins/basic_snmp.py	70769aabb99d393217f8760c13214b38696921ed
@@ -3,6 +3,8 @@
 # basic_snmp : stuff a generic managed switch should support
 #

+from goatpy.snmpwrapper import snmpwalk
+
 plugin_info = {
     'description' : '''\
 A basic module, which provides as many tables as possible without
@@ -11,20 +13,47 @@ that exports the required MIBs.
 '''
 }

-def ethernet_forwarding(table_name, table_io, device):
-    yield device.config['zone'], 1, '00:11:24:c7:dd:41', 'en1', now()
+def ip_arp(table_name, table_io, device):
+	for oid, type, value in snmpwalk(device.device_name, device.config['community'], "2c", "IP-MIB::ipNetToMediaPhysAddress", ssh_dest=device.config.get('ssh')):
+		ip_address = '.'.join(oid[-4:])
+		mac_address = value
+		yield device.config['zone'], None, mac_address, ip_address

-def ethernet_arp(table_name, table_io, device):
-    return None
+def ip_routing(hostname, community):
+	routes = {}
+	for oid, route_type, value in snmpwalk(hostname, community, "2c", "ipRouteTable"):
+		row_name = oid[0]
+		colon = row_name.rfind(':')
+		if colon <> -1: row_name = row_name[colon+1:]
+		ip_address = '.'.join(oid[-4:])
+		if not routes.has_key(ip_address): routes[ip_address] = {}
+		routes[ip_address][row_name] = value
+	for row in routes:
+		route = routes[row]
+		route_type = route.get('ipRouteType')
+		if route_type:
+			m = re.match(r'([a-zA-Z]+)\(', route_type)
+			if m:
+			    route_type = m.groups()[0]
+		if route.has_key('ipRouteDest') and route.has_key('ipRouteMask'):
+			network = route.get('ipRouteDest') + '/' + str(int_to_length(ip_to_int(route.get('ipRouteMask'))))
+		else: network = None
+		via = route.get('ipRouteNextHop')
+		metric = route.get('ipRouteMetric1')
+		ifindex = route.get('ipRouteIfIndex')
+		if ifindex: ifindex = int(ifindex)
+		yield route_type, ifindex, False, network, via, metric

+def ethernet_forwarding(table_name, table_io, device):
+    yield device.config['zone'], 1, '00:11:24:c7:dd:41', 'en1'

 tables = {
     'ethernet_forwarding' : ethernet_forwarding,
-    'ethernet_arp' : ethernet_arp,
+    'ip_arp' : ip_arp,
+    'ip_routing' : ip_routing,
 }

 def init():
     export['has_table'] = simple_has_table(tables)
     export['get_table'] = simple_get_table(tables)
     log("basic snmp initialised")
-
============================================================
--- plugins/cisco_ios.py	da39a3ee5e6b4b0d3255bfef95601890afd80709
+++ plugins/cisco_ios.py	435cb5aa7252bf973200b392a7465de7321766a8
@@ -0,0 +1,13 @@
+
+from basic_snmp import ip_arp, ethernet_forwarding
+
+
+tables = {
+    'ethernet_forwarding' : ethernet_forwarding,
+    'ip_arp' : ip_arp,
+}
+
+def init():
+    export['has_table'] = simple_has_table(tables)
+    export['get_table'] = simple_get_table(tables)
+    log("Cisco IOS initialised")
============================================================
--- tables/ethernet_forwarding.csv	91a6649f3ceeea0276a7d8a73639a28943af92d3
+++ tables/ethernet_forwarding.csv	b7e1c7e10c68fdc6d544255a2d13ea7460c859cc
@@ -1 +1 @@
-"zone","vlan","ethernet_address","interface","epoch_time"
+"zone","vlan","ethernet_address","interface"
============================================================
--- yowie.py	ef2df1fc34094e09a0c1cb771c03dbd744a8c933
+++ yowie.py	3e57b46eee9446cfb98f258c312df9df5a5cb8a6
@@ -1,7 +1,8 @@
 #!/usr/bin/env python2.4

-import socket
 import config
+import popen2
+import socket
 import pipes
 import time
 import csv
@@ -99,11 +100,27 @@ end
 end
 ''' % config.mtn_passphrase)

-def monotone_commit():
+empty_diff = '# \n# no changes\n# \n'
+
+def monotone_add():
     os.chdir(config.data_path)
     rv = s(mtn_cmd + " add .")
     if rv != 0:
         raise Exception("monotone add failed")
+
+def monotone_diff():
+    os.chdir(config.data_path)
+    diff = popen2.popen2(mtn_cmd + ' diff')[0].read()
+    try: os.wait()
+    except: pass
+    if diff == empty_diff:
+        return None
+    else:
+        return diff
+
+def monotone_commit():
+    os.chdir(config.data_path)
+    os.system('mtn diff')
     commit_message = "yowie.py on %s : automatic commit" % (socket.gethostname())
     rv = s(mtn_branch_cmd + " -k %s --message=%s commit" % (pq(config.mtn_key), pq(commit_message)))
     if rv != 0:
@@ -173,7 +190,10 @@ if __name__ == '__main__':
     tables = init_tables()
     map(update_device, devices)
     # commit changes to the data repository
+    monotone_add()
+    diff = monotone_diff()
+    if diff:
+        log("changes detected: committing to repository")
+        monotone_commit()
+    else:
+        log("no changes: skipping commit")
-    monotone_commit()
-
-
-