def add_node(logger, args): logger.debug("action: add_node") p = argparse.ArgumentParser(usage="%(prog)s add_node IP PLUGIN [-u USERNAME] [-p PASSWORD]") p.add_argument("ip") p.add_argument("plugin") p.add_argument("-u", "--username") p.add_argument("-p", "--password") o, a = p.parse_known_args(args) logger.debug("action opts: %s", o) logger.debug("action args: %s", a) if o.ip and o.plugin: try: load_plugin(o.plugin) except ImportError: logger.error("%s is not a valid plugin", o.plugin) sys_exit(1) node = Node(o.ip, o.plugin) try: session.add(node) node.username = o.username node.password = o.password session.commit() logger.info("Node added") except IntegrityError: logger.error("Node already exists") sys_exit(1)
"DS:val:GAUGE:120:-100:100", # Accept data between -100 and +100 as valid "RRA:AVERAGE:0.5:1:525600", # A year of minutes "RRA:AVERAGE:0.5:60:8760", # A year of hours "RRA:MAX:0.5:60:8760", # A year of hours "RRA:MIN:0.5:60:8760", # A year of hours ) #update data rrdtool.update(rrd, "N:" + str(value)) #store latest values try: (n, x, y, z, h, w, d) = sensors[serial] except IndexError: (n, x, y, z, h, w, d) = ("Auto-detected " + name, 0, 0, 0, 0, 0, 0) session.add(Probe(serial, n, x, y, z, h, w, d)) # Update timestamp probe = session.query(Probe).filter(Probe.id == serial).first() if (probe.name <> n): print("Mismatch of name against node %s vs %s" % (probe.name, n)) probe.lastcontact = datetime.now() probe.remote_name = name probe.node = source_node row = [serial, value, n, x, y, h, w] snapshot_list.append(row) # Commit outside loop