def availability(resource, status) : # TUB server oml = OMLBase("myops2","PLE","PLETestbed","tcp:193.175.132.241:3003") oml.mpprefix = False oml.addmp("availability", "node:string up:double last_check:string") oml.start() oml.inject("availability", (resource, status, datetime.now().isoformat() + "+01:00")) oml.close()
class TestOmlClient(threading.Thread): def __init__(self, interval=10): threading.Thread.__init__(self, name=APPLICATION_NAME) self.__mutex = threading.Lock() self.__stop = threading.Event() self.__interval = int(interval) self.daemon = True self.oml = OMLBase(APPLICATION_NAME, DOMAIN, IDENTIFIER, URL) self.start() def define_measurements(self): msformat = "freq:string amplitude:int32" self.oml.addmp(MEASUREMENT_POINT_NAME, msformat) print "%s: defined measurements format=%s" %\ (MEASUREMENT_POINT_NAME, msformat) def action(self): tmp = [random.choice(S.ascii_letters + S.digits) for n in xrange(32)] data = [''.join(tmp), random.randint(0, 100)] self.oml.inject(MEASUREMENT_POINT_NAME, data) print "%s: sent data to collector=%s" % (MEASUREMENT_POINT_NAME, data) def run(self): print 'Run TestOmlClient' self.define_measurements() self.oml.start() try: while self.__isStopped() is False: self.action() print 'Waiting %dsecs' % (self.__interval) time.sleep(self.__interval) except Exception as e: print "Run error: %s" % str(e) finally: print "close communication to collector" self.oml.close() def loop(self, secs): while self.is_alive(): self.join(secs) def stop(self): with self.__mutex: self.__stop.set() def __isStopped(self): with self.__mutex: return self.__stop.isSet()
def run (): for server in config.FACILITY_MON_SERVERS: oml=OMLBase(config.FM_APP, config.DOMAIN, config.SENDER, server) # MP for Controller Ping oml.addmp("icmp","node:string up:double last_check:string") # MP for Controller Http server (website) oml.addmp("http","node:string up:double last_check:string") controller_ping_up = ping_ipv4_is_ok(config.CLAB_CONTROLLER_IPv4) controller_http_up = website_is_ok(config.CLAB_CONTROLLER_URL) monitor_ping_up = ping_ipv4_is_ok(config.CLAB_MONITOR_IPV4) timestamp = current_timestamp() oml.start() oml.inject("icmp", ("controller", controller_ping_up, timestamp)) oml.inject("http", ("controller", controller_http_up, timestamp)) oml.close() print current_timestamp()+" - Facilitity Monitoring: data sent to "+server
class Agent(threading.Thread): __metaclass__ = ABCMeta @abstractmethod def define_measurements(self): pass @abstractmethod def action(self): pass def __init__(self, name, domain, id_, collector, interval, logger=None): threading.Thread.__init__(self, name=name) self.__mutex = threading.Lock() self.__stop = threading.Event() self.__logger = logger self.__interval = int(interval) self.daemon = True self.oml = OMLBase(name, domain, id_, collector) self.start() def loop(self, secs): while self.is_alive(): self.join(secs) def run (self): self.__debug("Run agent base object") self.define_measurements() self.oml.start() try: while self.__isStopped() == False: self.action() self.__debug("Waiting %dsecs before perform an action" % (self.__interval,)) time.sleep(self.__interval) except Exception as e: self.error("Run error: %s" % (str(e),)) finally: self.__debug("close communication to collector") self.oml.close() def stop(self): with self.__mutex: self.__stop.set() def info(self, msg): if self.__logger: self.__logger.info(msg) def error(self, msg): if self.__logger: self.__logger.error(msg) def __debug(self, msg): if self.__logger: self.__logger.debug(msg) def __isStopped(self): with self.__mutex: return self.__stop.isSet()