Skip to content

Commit

Permalink
Fix pylint warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
jiuka committed May 3, 2023
1 parent af65bb7 commit 57c4a02
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
33 changes: 19 additions & 14 deletions agent_based/netbox_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

from datetime import datetime


def parse_netbox_reports(string_table):
parsed = {}

Expand All @@ -64,54 +65,58 @@ def parse_netbox_reports(string_table):
# print (parsed)
return parsed


register.agent_section(
name = "netbox_reports",
parse_function = parse_netbox_reports,
)


def discover_netbox_reports(section):
for name in section:
yield Service(item=name)


def check_netbox_reports(item, params, section):

report = section[item]

now = datetime.now()
if not 'last_run' in report:
if 'last_run' not in report:
yield Result(state=State.UNKNOWN, summary=(f"Report \"{item}\" not yet executed"))
else:
age = now - report['last_run']
yield from check_levels(
value=age.total_seconds(),
levels_upper=params.get('maxage', None),
render_func=lambda f: render.timespan(f if f > 0 else -f),
label='Last Run' if age.total_seconds() > 0 else "Last Run in",
)
value=age.total_seconds(),
levels_upper=params.get('maxage', None),
render_func=lambda f: render.timespan(f if f > 0 else -f),
label='Last Run' if age.total_seconds() > 0 else "Last Run in",
)

for test_name in report:
if test_name == 'last_run':
continue

yield Result(state = State.OK, summary = f"{test_name}",
details = f"{test_name}: {report[test_name]['result']}")
details = f"{test_name}: {report[test_name]['result']}")

if report[test_name]['result']['warning'] > 0:
yield Result (state = State.WARN,
summary = f"Warning: {report[test_name]['result']['warning']}")
yield Result(state = State.WARN,
summary = f"Warning: {report[test_name]['result']['warning']}")

if report[test_name]['result']['failure'] > 0:
yield Result (state = State.WARN,
summary = f"Failure: {report[test_name]['result']['failure']}")
yield Result(state = State.WARN,
summary = f"Failure: {report[test_name]['result']['failure']}")

for key, value in report[test_name]['result'].items():
yield Metric (f"{test_name}_{key}", value)
yield Metric(f"{test_name}_{key}", value)


register.check_plugin(
name = "netbox_reports",
service_name = "Netbox Reports %s",
discovery_function = discover_netbox_reports,
check_function = check_netbox_reports,
check_ruleset_name = "netbox_reports",
check_default_parameters = {'maxage': (2*24*3600, 7*24*3600)},
)
check_default_parameters = {'maxage': (2 * 24 * 3600, 7 * 24 * 3600)},
)
3 changes: 2 additions & 1 deletion web/plugins/wato/check_parameters_netbox_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
RulespecGroupCheckParametersApplications,
)


def _item_spec_netbox_reports():
return TextAscii(title=_('Name of the Netbox Report'),
allow_empty=False)
Expand Down Expand Up @@ -63,4 +64,4 @@ def _parameter_valuespec_netbox_reports():
match_type='dict',
parameter_valuespec=_parameter_valuespec_netbox_reports,
title=lambda: _('Netbox Reports'),
))
))
2 changes: 1 addition & 1 deletion web/plugins/wato/datasource_netbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ def _valuespec_special_agents_netbox():
group=RulespecGroupDatasourceProgramsApps,
name='special_agents:netbox',
valuespec=_valuespec_special_agents_netbox,
))
))

0 comments on commit 57c4a02

Please sign in to comment.