Ejemplo n.º 1
0
    def __init__(self, cfg):
        """
        Constructor method when the object is initialized

        :param cfg: Specifies the configuration file that will be used to process the data
        :return: nothing
        """
        self.cfg = cfg
        self.zeusToken = cfg.get("zeus", "token")
        self.logName = cfg.get("zeus", "log_name")
        self.logKey = cfg.get("zeus", "log_key")
        self.zeusServer = cfg.get("zeus", "url")
        self.client = client.ZeusClient(self.zeusToken, self.zeusServer)

        # Call the base class initializer
        super(CiscoZeusAlert, self).__init__()
Ejemplo n.º 2
0
    def set_up(self):
        # get arguments
        self.args = self.get_args()

        # set log level
        self.set_log_level(self.args.log_level)

        self.host = self.args.ucs
        if self.args.secure == True:
            self.url = 'https://%s/nuova' % self.args.ucs
        else:
            self.url = 'http://%s/nuova' % self.args.ucs
        self.user = self.args.user
        self.passwd = self.args.password

        self.token = self.args.token
        self.zeus_server = self.args.zeus

        # set up a Zeus client to submit log to Zeus.
        self.logger.info("Initiating Zeus connection...")
        self.zeus_client = client.ZeusClient(self.token, self.zeus_server)

        # set up a http client to UCS server.
        self.logger.info("Initiating UCSM connection...")
        self.handler = UcsHandle(self.host,
                                 self.user,
                                 self.passwd,
                                 port=self.args.port,
                                 secure=self.args.secure)
        # login to ucs
        self.handler.login(auto_refresh=True)
        self.add_log("DEBUG",
                     "ucs",
                     msg={
                         "User": self.user,
                         "Password": self.passwd,
                         "cookie": self.handler.cookie
                     })
        self.logger.info("Login UCSM completed.")

        self.logger.info("Getting configuration data...")
        self.get_dn_conf()

        self.logger.info("Listening to UCSM events...")
        self.event_loop()
Ejemplo n.º 3
0
 def __init__(self):
     self.api = client.ZeusClient(os.getenv("ZEUS_TOKEN"),
                                  os.getenv("ZEUS_API_HOST"))
     self.log = os.getenv("ZEUS_KEY")
     self.key = os.getenv("ZEUS_KEY")
 def test_initialization_no_http(self):
     z = client.ZeusClient(FAKE_TOKEN, "zeus.rocks")
     assert z.server == "http://zeus.rocks"
 def setUp(self):
     # Setting up a Zeus client with a fake token:
     self.z = client.ZeusClient(FAKE_TOKEN, FAKE_SERVER)
Ejemplo n.º 6
0
 def setUp(self):
     self.ucs_agent = UCSAgent()
     self.ucs_agent.set_log_level(LOG_LEVEL)
     self.ucs_agent.zeus_client = client.ZeusClient(ZEUS_TOKEN, ZEUS_SERVER)
     self.original_get_dn_conf = UCSAgent.get_dn_conf
Ejemplo n.º 7
0
def generate_entry(timeval, conf):
    ret_json = {"@timestamp": timeval.isoformat()}
    for field_name, field_config in conf.items():
        try:
            ret_json[field_name] = call_func(field_config)
        except:
            print("Error generating '" + field_name + "', type '" +
                  field_config[0] + "'")
            raise
    return ret_json


modified_config = {}
if not args.dry_run:
    z = client.ZeusClient(zeus_token, 'api.ciscozeus.io')
for field_name, field_config in in_config.items():
    mod_field_config = check_field(field_name, field_config)
    modified_config[field_name] = mod_field_config
if timestamp_config["generate"] == "one-time":
    curr_time = get_datetime(timestamp_config["start_time"])
    total_delay = 0
    while (total_delay < timestamp_config["duration"]):
        next_json = generate_entry(curr_time, modified_config)
        try:
            print(json.dumps(next_json))
            if not args.dry_run:
                z.sendLog("temperature", [next_json])
        except:
            print("Problem sending output " + str(next_json))
            raise