Skip to content

Commit

Permalink
Improvements to logging behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-eisenhart committed Jun 6, 2024
1 parent 44e09a9 commit 653b7c8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
11 changes: 7 additions & 4 deletions src/sonic/netbox_zabbix/netbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,22 @@ class SonicNetboxZabbix_Netbox:
"""

log = False
config = False

def __init__(self, logger, config):
def __init__(self, logger, configobj):
global log
global config

self.log = logger
self.config = config
self.config = configobj

log = self.log
config = self.config

log.debug("Logging into Netbox")
self.api = pynetbox.api(
self.config.netboxurl,
token=self.config.netboxtoken,
config.netboxurl,
token=config.netboxtoken,
threading=True,
)

Expand Down
27 changes: 18 additions & 9 deletions src/sonic/netbox_zabbix/zabbix.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ class SonicNetboxZabbix_Zabbix:
"""

log = False
config = False

def __init__(self, logger, config):
def __init__(self, logger, configobj):
global log
global config

self.log = logger
self.config = config
self.config = configobj

log = self.log
config = self.config

# self.log.info("Logging into Zabbix")
api = ZabbixAPI(self.config.zabbixurl)
Expand Down Expand Up @@ -68,10 +72,11 @@ def hostgroup_site_get_or_create(self, name):
log.debug(f"{name}:sites[0]:{sites[0]}")
groupid = sites[0]["groupid"]
else:
log.debug(f"TRACE:create group:{name}")
if config.verbose >= 4:
log.debug(f"TRACE:create group:{name}")
groupid = self.api.hostgroup.create(name=name)["groupids"][0]

log.debug(f"DEBUG:returning groupid:{groupid}")
log.debug(f"returning groupid:{groupid}")
return {"groupid": int(groupid)}

def host_update_tags(self, hostid, tags):
Expand All @@ -90,28 +95,32 @@ def host_update_macros(self, hostid, macros):
return response

def host_update_hostgroups(self, hostid, hostgroups):
log.debug(f"TRACE:{hostid}:hostgroups:{hostgroups}")
if config.verbose >= 4:
log.debug(f"TRACE:{hostid}:hostgroups:{hostgroups}")
response = self.api.host.update(hostid=hostid, groups=hostgroups)
log.debug(f"{hostid}:response:{pformat(response)}")
return response

def host_disable(self, host):
hostid=host["hostid"]
log.debug(f"TRACE:{hostid}")
if config.verbose >= 4:
log.debug(f"TRACE:{hostid}")
# log.debug(f"TRACE:host:pformat:{pformat(host)}")
if int(host["status"]) != 1:
log.warning(f"Disabling host {host["name"]}/{hostid}")
response = self.api.host.update(hostid=hostid, status=1)
log.debug(f"{hostid}:response:{pformat(response)}")
return response
else:
self.log.debug(f"Already disabled host {host["name"]}/{hostid}")
log.info(f"Already disabled host {host["name"]}/{hostid}")
return False

def host_enable(self, host):
hostid=host['hostid']
log.debug(f"TRACE:{hostid}")
# log.debug(f"TRACE:host:pformat:{pformat(host)}")
if config.verbose >= 4:
log.debug(f"TRACE:{hostid}")
if config.verbose >= 5:
log.debug(f"TRACE:host:pformat:{pformat(host)}")
if int(host["status"]) != 0:
log.warning(f"Enabling host {host["name"]}/{hostid}")
response = self.api.host.update(hostid=hostid, status=0)
Expand Down

0 comments on commit 653b7c8

Please sign in to comment.