Skip to content

Commit

Permalink
adds value offset
Browse files Browse the repository at this point in the history
  • Loading branch information
gurubert committed Sep 4, 2024
1 parent bbdad4d commit bdb40f8
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 2 deletions.
Binary file removed check_snmp_metric/check_snmp_metric-0.4.4.mkp
Binary file not shown.
Binary file added check_snmp_metric/check_snmp_metric-0.5.0.mkp
Binary file not shown.
3 changes: 3 additions & 0 deletions check_snmp_metric/checks/check_snmp_metric
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ def check_snmp_metric_arguments(params):
if "factor" in params:
args += ' --factor %f' % params["factor"]

if "offset" in params:
args += ' --offset %f' % params["offset"]

if "unit" in params:
args += ' --unit %s' % quote_shell_string(params["unit"])

Expand Down
5 changes: 4 additions & 1 deletion check_snmp_metric/lib/nagios/plugins/check_snmp_metric
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ from pprint import pprint

snmpgetcmd=['snmpget', '-O', 'nq']
factor=1.0
offset=0.0
unit=""
warn=0
warnset=False
Expand All @@ -43,6 +44,8 @@ while args:
a = args.pop(0)
if a == "--factor":
factor=float(args.pop(0))
elif a == "--offset":
offset=float(args.pop(0))
elif a == "--unit":
unit=args.pop(0)
elif a == "--metric":
Expand Down Expand Up @@ -72,7 +75,7 @@ res = exec_snmpget(snmpgetcmd)

if res.returncode == 0:
oid, v = res.stdout.strip().split()
val = float(v) / factor
val = (float(v) / factor) + offset
state = 0
info = '%s is %0.2f %s' % (oid, val, unit)
if critset and val > crit:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ def _valuespec_active_checks_snmp_metric():
help = _("A Factor of 10 means that the value reported is ten times the real value, e.g. the OID contains 245, but the real temperature is 24,5°C"),
default_value = 1.0,
)),
( "offset",
Float(
title = _("Value offset"),
help = _("An offset that gets added (with a positive value) to the value or subtracted (with a negative value) from the value after applying the value factor."),
default_value = 0.0,
)),
( "metric",
TextAscii(
title = _("Metric name"),
Expand All @@ -114,7 +120,7 @@ def _valuespec_active_checks_snmp_metric():
help = _("Unit of the value. Used for display."),
)),
],
optional_keys = [ 'hostname', 'port', 'timeout', 'creds', 'levels_upper', 'levels_lower', 'factor', 'metric', 'unit', ],
optional_keys = [ 'hostname', 'port', 'timeout', 'creds', 'levels_upper', 'levels_lower', 'factor', 'offset', 'metric', 'unit', ],
)

rulespec_registry.register(
Expand Down

0 comments on commit bdb40f8

Please sign in to comment.