def update_probe(logger, args): logger.debug("action: update_probe") p = argparse.ArgumentParser(usage="%(prog)s update_probe [options]") p.add_argument("id", help="probe id") p.add_argument("-n", help="name") p.add_argument("-x", help="x position") p.add_argument("-y", help="y position") p.add_argument("-z", help="z position") p.add_argument("-w", help="width") p.add_argument("-d", help="depth") p.add_argument("-t", help="height") o, a = p.parse_known_args(args) logger.debug("action opts: %s", o) logger.debug("action args: %s", a) if o.n is o.x is o.y is o.z is o.w is o.d is o.t is None: p.print_help() else: probe = session.query(Probe).filter(Probe.id == o.id).first() # Try name if id doesn't match any probes if not probe: logger.info("No probe found with id '%s', trying to match by name", o.id) probe = session.query(Probe).filter(Probe.name == o.id).all() if len(probe) > 1: logger.error("%d probes found with the name '%s', use ID to update each in turn", len(probe), o.id) for p in probe: print p sys_exit(1) probe = probe[0] if probe: if o.n: probe.name = o.n if o.x: probe.x = o.x if o.y: probe.y = o.y if o.z: probe.z = o.z if o.w: probe.w = o.w if o.t: probe.h = o.t if o.d: probe.d = o.d session.commit() logger.info("Probe updated") else: logger.error("No probe found with id or name '%s'", o.id)
def list_probes(logger, opts): logger.debug("action: list_probes") probes = session.query(Probe).all() if opts.format == "json": o = [] for p in probes: o.append(p.list()) o = { "aaData" : o } print(json.dumps(o)) else: for p in probes: print(p)
def list_nodes(logger, opts): logger.debug("action: list_nodes") nodes = session.query(Node).all() if opts.format == "json": o = [] for n in nodes: o.append(n.list()) o = { "aaData" : o } print(json.dumps(o)) else: for n in nodes: print(n)
def remove_node(logger, args): logger.debug("action: remove_node") p = argparse.ArgumentParser(usage="%(prog)s remove_node IP") p.add_argument("ip") o, a = p.parse_known_args(args) logger.debug("action opts: %s", o) logger.debug("action args: %s", a) if o.ip: node = session.query(Node).filter(Node.ip == o.ip).first() if node: session.delete(node) session.commit() logger.info("Node removed") else: logger.error("No node found with the IP %s", o.ip)
try: import simplejson as json except ImportError: print("ERROR: Unable to find a usable json module, is simplejson installed?") sys.exit(1) #ARTEMIS Components from artemis_core import grabData, load_plugin #Load config module from artemis_config import config, session, Node, Probe # Setup base nodes from store base_nodes = [] for n in session.query(Node).all(): base_nodes.append(load_plugin(n.plugin)(n.ip, n.username, n.password)) # Setup sensors from store sensors = {} for p in session.query(Probe).all(): sensors[p.id] = [p.name, float(p.x), float(p.y), float(p.z), float(p.w), float(p.h), float(p.d)] #Configuration this_dir = os.path.dirname(os.path.realpath( __file__ )) + "/" rrd_dir = this_dir + config.get("rrd","dir") print("Starting run...") #Start collection