#!/usr/bin/python """ This application gathers the local machines IP Addresses and their matching labels. Thereafter, it will notify, via callback, any IP address changes. """ import socket import struct import sys import thread import time from highlander_agent.common import log from highlander_agent.common.constants import Constant LOGGER = log.getLogger(Constant.LOGGER_MONITOR) """4 byte alignment""" def align(inc): diff = inc % 4 return inc + ((4 - diff) % 4) class iflink: """Parse an iflink packet""" # https://www.kernel.org/doc/Documentation/networking/operstates.txt # Routing Attributes for link IFLA_UNSPEC = 0 IFLA_ADDRESS = 1 IFLA_BROADCAST = 2
import sys import time import os import atexit from signal import SIGTERM from highlander_agent.common.constants import Constant from highlander_agent.common import log LOGGER = log.getLogger(Constant.LOGGER_LISTENER) # logging.debug('This message should go to the log file') # logging.info('So should this') # logging.warning('And this, too') class HighlanderListenerDaemon: """ A generic daemon class. Usage: subclass the Daemon class and override the run() method """ startmsg = "Listener server started with pid %s" """ A generic daemon class. Usage: subclass the Daemon class and override the run() method """ def __init__(self, pidfile, stdin='/dev/null', stdout='/dev/null', stderr='/dev/null'):
import simplejson import pika from highlander_agent.common import log from highlander_agent.common.constants import Constant from highlander_agent.engine.default_agent import DefaultAgentService from highlander_agent.rpcserver.daemon import HighlanderRPCDaemon from highlander_agent.rpcserver.endpoint import RPCEndpoint from highlander_agent.rpcserver.server import RPCServer LOGGER = log.getLogger(Constant.LOGGER_RPC_SERVER) EVENT_LOGGER = log.getLogger(Constant.LOGGER_EVENT) class DefaultRPCServer(HighlanderRPCDaemon, RPCServer): def __init__(self, cfg, log_name=None): HighlanderRPCDaemon.__init__( self, cfg[Constant.CONFIG_PIDFILE_SECTION]["server"]) RPCServer.__init__(self, cfg) self.cfg = cfg self._defaultagentservice = DefaultAgentService(cfg) def run(self): self.start_rpc() def getconfig(self, instanceid): return self._defaultagentservice.getconfig() def getagentconfig(self, dummy=None):
import timeit import uuid import pika from highlander_agent.common import log from highlander_agent.common.constants import Constant LOGGER = log.getLogger(Constant.LOGGER_RPC_SERVER) class API(object): def __init__(self, cfg, agent_hostname=None): self._cfg = cfg self.credentials = pika.PlainCredentials( self._cfg["RabbitMQ"]["username"], self._cfg["RabbitMQ"]["secret"]) if agent_hostname is None: self.routing_key = self._cfg["RPCServer"]["routing_key"] else: self.routing_key = str( self._cfg["RPCServer"]["routing_key_raw"]).replace( "[]", agent_hostname) self.exchange = self._cfg["RPCServer"]["exchange"] self.response = None self.corr_id = None self.connection = pika.BlockingConnection( pika.ConnectionParameters(self._cfg["RabbitMQ"]["host"], int(self._cfg["RabbitMQ"]["port"]), '/', self.credentials))
# If ../highlander_agent/__init__.py exists, add ../ to Python search path, so that # it will override what happens to be installed in /usr/(local/)lib/python... POSSIBLE_TOPDIR = os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir, os.pardir, os.pardir)) if os.path.exists(os.path.join(POSSIBLE_TOPDIR, 'highlander_agent', '__init__.py')): sys.path.insert(0, POSSIBLE_TOPDIR) from highlander_agent.monitor.daemon import HighlanderMonitorDaemon import time from highlander_agent.common.util import AgentConfigParser from highlander_agent.common.constants import Constant from highlander_agent.common import log from highlander_agent.notifier import send from highlander_agent.rules import instance LOGGER = log.getLogger(Constant.LOGGER_MONITOR) FAILURE_LOGGER = log.getLogger(Constant.LOGGER_FAILURE) class InstanceMonitor(HighlanderMonitorDaemon): def __init__(self, pidfile, instance_configuration_json=None, cfg=None): HighlanderMonitorDaemon.__init__(self, pidfile, instance_configuration_json) self._cfg = cfg self._instance_name = None if instance_configuration_json is not None: for instance in self._instances: if instance['id'] == self._instance_id_to_monitor: LOGGER.warn("Attempting to find QEMU process with instance name '%s' for instance %s" % ( instance['name'], self._instance_id_to_monitor)) self._instance_name = instance['name']
import json import os import sys import time from highlander_agent.common import log from highlander_agent.common.constants import Constant from highlander_agent.common.util import AgentConfigParser from highlander_agent.rpcclient.api import API LOGGER = log.getLogger(Constant.LOGGER_MONITOR) EVENT_LOGGER = log.getLogger(Constant.LOGGER_EVENT) class Rules(): @staticmethod def publish(routing_key, jsondata, instances=None, notifier=None): if notifier is not None: notifier.reinit(routing_key, '', '') if instances is not None: notifier.notify({ "return_code": 501, "id": instances["id"], "message": jsondata }) else: notifier.notify({ "return_code": 501, "id": jsondata, "message": jsondata })