Index: tools/check-batch-cmd
===================================================================
--- tools/check-batch-cmd	(revision 10424)
+++ tools/check-batch-cmd	(revision 10433)
@@ -9,5 +9,4 @@
 import gformat
 import getpass
-import netsnmp
 import os
 import paramiko
@@ -17,12 +16,42 @@
 
 SSHPASS = None
-netsnmp.verbose = 0
+import pysnmp
+from pysnmp.entity.rfc3413.oneliner import cmdgen
+
+def snmp_test():
+  errorIndication, errorStatus, errorIndex, varBinds = cmdgen.CommandGenerator().getCmd(
+      # SNMP v1
+  #    cmdgen.CommunityData('test-agent', 'public', 0),
+      # SNMP v2
+      cmdgen.CommunityData('test-agent', 'public'),
+      # SNMP v3
+  #    cmdgen.UsmUserData('test-user', 'authkey1', 'privkey1'),
+      cmdgen.UdpTransportTarget(('localhost', 161)),
+      # Plain OID
+      (1,3,6,1,2,1,1,1,0),
+      # ((mib-name, mib-symbol), instance-id)
+      (('SNMPv2-MIB', 'sysObjectID'), 0)
+      )
+  
+  if errorIndication:
+      print errorIndication
+  else:
+      if errorStatus:
+          print '%s at %s\n' % (
+              errorStatus.prettyPrint(),
+              errorIndex and varBinds[int(errorIndex)-1] or '?'
+              )
+      else:
+          for name, val in varBinds:
+              print '%s = %s' % (name.prettyPrint(), val.prettyPrint())
+
+
 
 class CmdError(Exception):
   pass
 
-def check_host(hostname):
-  cmd = "cat /etc/board.info"
-  
+
+
+def host_ssh_cmd(hostname, cmd):
   ssh = paramiko.SSHClient()
   ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
@@ -32,8 +61,15 @@
   stderr = stderr.readlines()
   ssh.close()
-  if stderr: 
-    raise CmdError(stderr)
- 
-  return dict(map(lambda x: x.strip().split('='),stdout))
+  if stderr:
+    raise CmdError((stderr, stdout))
+  return stdout
+
+def parse_ini(lines):
+  return dict(map(lambda x: x.strip().split('='),lines))
+
+def ubnt_probe(hostname):
+  items = parse_ini(host_ssh_cmd(hostname, 'cat /etc/board.info'))
+  print items
+
 
 def get_bridge_type(host):
@@ -51,28 +87,37 @@
 
 
-def update_hosts(filters=[]):
-  for host in gformat.get_hostlist():
-    if filters and not any([f.lower() in host.lower() for f in filters]):
-      continue
-
-    print "# Processing host", host
-    datadump = gformat.get_yaml(host)
-    for iface_key in datadump['autogen_iface_keys']:
-      ifacedump = datadump[iface_key]
-      if ifacedump.has_key('ns_ip') and ifacedump['ns_ip']:
-        addr = ifacedump['ns_ip'].split('/')[0]
-        print "## Bridge IP: %(ns_ip)s at %(interface)s" % ifacedump
-        try:
-          socket.create_connection((addr,80),2)
-          bridge_type = get_bridge_type(addr)
-          datadump[iface_key]['bridge_type'] = bridge_type
-        except (socket.timeout, socket.error) as e:
-          print "### %s (%s)" % (e, addr)
-        except paramiko.AuthenticationException:
-          print "### Conection failed (invalid username/password)"
-        except CmdError, e: 
-          print "### Command error: %s" % e
-    gformat.store_yaml(datadump)
-        
+def node_check(host):
+  print "# Processing host", host
+  datadump = gformat.get_yaml(host)
+  output = host_ssh_cmd(datadump['autogen_fqdn'], 'cat /var/run/dmesg.boot')
+
+  # Get board Type
+  for line in [x.strip() for x in output]:
+    if line.startswith('CPU:'):
+      print line
+    elif line.startswith('Geode LX:'):
+      datadump['board'] = 'ALIX2'
+      print line
+    elif line.startswith('real memory'):
+      print line
+    elif line.startswith('Elan-mmcr'):
+      datadump['board'] = 'net45xx'
+  #for iface_key in datadump['autogen_iface_keys']:
+  #  ifacedump = datadump[iface_key]
+  #  if ifacedump.has_key('ns_ip') and ifacedump['ns_ip']:
+  #    addr = ifacedump['ns_ip'].split('/')[0]
+  #    print "## Bridge IP: %(ns_ip)s at %(interface)s" % ifacedump
+  #    try:
+  #      socket.create_connection((addr,80),2)
+  #      bridge_type = get_bridge_type(addr)
+  #      datadump[iface_key]['bridge_type'] = bridge_type
+  #    except (socket.timeout, socket.error) as e:
+  #      print "### %s (%s)" % (e, addr)
+  #    except paramiko.AuthenticationException:
+  #      print "### Conection failed (invalid username/password)"
+  #    except CmdError, e: 
+  #      print "### Command error: %s" % e
+  gformat.store_yaml(datadump)
+
 
 def make_output(stdout, stderr):
@@ -125,16 +170,14 @@
   subparsers = parser.add_subparsers(help='sub-command help')
   
-  parser_snmp = subparsers.add_parser('snmp', help='enable SNMP on UBNT')
+  parser_snmp = subparsers.add_parser('bridge', help='UBNT Bridge Management')
+  parser_snmp.add_argument('action', type=str, choices=['keys', 'snmp', 'probe'])
   parser_snmp.add_argument('host',type=str)
-  parser_snmp.set_defaults(func='snmp')
-  
-  parser_keys = subparsers.add_parser('keys', help='add ssh keys on UBNT')
-  parser_keys.add_argument('host', type=str)
-  parser_keys.set_defaults(func='keys')
-
-  parser_update = subparsers.add_parser('update', help='process all UBNT')
-  parser_update.add_argument('filters', default=None, nargs='*', type=str)
-  parser_update.set_defaults(func='update')
-  
+  parser_snmp.set_defaults(func='bridge')
+  
+  parser_node = subparsers.add_parser('node', help='Proxy/Node/Hybrid Management')
+  parser_node.add_argument('action', type=str, choices=['check',])
+  parser_node.add_argument('host', type=str)
+  parser_node.set_defaults(func='node')
+
   args = parser.parse_args()
 
@@ -146,9 +189,18 @@
       SSHPASS = getpass.getpass("WL root password: ")
 
-
-  if args.func == 'keys':
-    ubnt_keys(args.host)
-  elif args.func == 'snmp':
-    ubnt_snmp(args.host)
-  elif args.func == 'update':
-    update_hosts(args.filters)
+  # XXX: We need this loop when using filters
+  #for host in gformat.get_hostlist():
+  #  if filters and not any([f.lower() in host.lower() for f in filters]):
+  #    continue
+
+
+  if args.func == 'bridge':
+    if args.action == 'keys':
+      ubnt_keys(args.host)
+    elif args.action == 'snmp':
+      ubnt_snmp(args.host)
+    elif args.action == 'probe':
+      ubnt_probe(args.host)
+  elif args.func == 'node':
+    if args.action == 'check':
+      node_check(args.host)
