Skip to content

Commit

Permalink
adjust cu() error messages, preventing duplicate tracebacks
Browse files Browse the repository at this point in the history
  • Loading branch information
NavidSassan committed Jul 13, 2023
1 parent a2e9306 commit 7fbe46e
Show file tree
Hide file tree
Showing 14 changed files with 42 additions and 42 deletions.
6 changes: 3 additions & 3 deletions check-plugins/borgbackup/borgbackup
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ from lib.globals import (STATE_CRIT, STATE_OK, # pylint: disable=C0413
STATE_UNKNOWN, STATE_WARN)

__author__ = 'Linuxfabrik GmbH, Zurich/Switzerland'
__version__ = '2023071203'
__version__ = '2023071301'

DESCRIPTION = '''Checks the date and return code of the last borgbackup, according to the logfile.
`cat /var/log/borg/borg-prune.log`
Expand Down Expand Up @@ -121,8 +121,8 @@ def main():
endtime
create_retc
prune_retc
except UnboundLocalError as e:
lib.base.cu('Could not find all expected values in the logfile.\n{}'.format(e))
except UnboundLocalError:
lib.base.cu('Could not find all expected values in the logfile.')

# We ignore retc 1, as it means operation reached its normal end, but there were warnings from borg.
state = STATE_OK
Expand Down
6 changes: 3 additions & 3 deletions check-plugins/countdown/countdown
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ from lib.globals import (STATE_CRIT, STATE_OK, # pylint: disable=C0413
STATE_UNKNOWN, STATE_WARN)

__author__ = 'Linuxfabrik GmbH, Zurich/Switzerland'
__version__ = '2023071203'
__version__ = '2023071301'

DESCRIPTION = 'Warns before an expiration date is scheduled to occur.'

Expand Down Expand Up @@ -116,8 +116,8 @@ def main():
# over and out
lib.base.oao(msg, state, always_ok=args.ALWAYS_OK)

except Exception as e:
lib.base.cu('Something seems to be wrong with the input parameter format or its timestamps. The error was: {}'.format(e))
except Exception:
lib.base.cu('Something seems to be wrong with the input parameter format or its timestamps')


if __name__ == '__main__':
Expand Down
6 changes: 3 additions & 3 deletions check-plugins/cpu-usage/cpu-usage
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ except ImportError:


__author__ = 'Linuxfabrik GmbH, Zurich/Switzerland'
__version__ = '2023071203'
__version__ = '2023071301'

DESCRIPTION = """Mainly provides utilization percentages for each specific CPU time. Takes a time
period into account: the cpu usage within a certain amount of time has to be equal
Expand Down Expand Up @@ -137,9 +137,9 @@ def main():
# https://github.com/Linuxfabrik/monitoring-plugins/issues/57: changed from 0.25 to 1.25
try:
cpu_times_percent = psutil.cpu_times_percent(interval=1.25, percpu=False)
except ValueError as e:
except ValueError:
lib.db_sqlite.close(conn)
lib.base.cu('psutil raised error "{}"'.format(e))
lib.base.cu('psutil raised an error')

# this is what we want to warn about: 100% - idle - nice
stats['cpu_usage'] = round(
Expand Down
4 changes: 2 additions & 2 deletions check-plugins/disk-io/disk-io
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ except ImportError as e:


__author__ = 'Linuxfabrik GmbH, Zurich/Switzerland'
__version__ = '2023071203'
__version__ = '2023071301'

DESCRIPTION = """Checks disk IO."""

Expand Down Expand Up @@ -149,7 +149,7 @@ def main():
try:
disk_io_counters = psutil.disk_io_counters(perdisk=True)
except ValueError as e:
lib.base.cu('psutil raised error "{}"'.format(e))
lib.base.cu('psutil raised an error')

now = lib.time.now()

Expand Down
4 changes: 2 additions & 2 deletions check-plugins/docker-stats/docker-stats
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ from lib.globals import (STATE_CRIT, STATE_OK, # pylint: disable=C0413
STATE_UNKNOWN, STATE_WARN)

__author__ = 'Linuxfabrik GmbH, Zurich/Switzerland'
__version__ = '2023071203'
__version__ = '2023071301'

DESCRIPTION = """This check prints various statistics for all running Docker containers, in much the
same way as the Unix application top, using the "docker stats" command."""
Expand Down Expand Up @@ -165,7 +165,7 @@ def main():
strpos2 = stdout.find('\n', strpos1)
host_cpus = int(stdout[strpos1:strpos2])
except:
lib.base.cu('{}'.format('Unable to compute docker info.'))
lib.base.cu('Unable to compute docker info')

# get the container statistics for all running containers
cmd = 'docker stats --no-stream'
Expand Down
6 changes: 3 additions & 3 deletions check-plugins/fs-inodes/fs-inodes
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ from lib.globals import (STATE_CRIT, STATE_OK, # pylint: disable=C0413
STATE_UNKNOWN, STATE_WARN)

__author__ = 'Linuxfabrik GmbH, Zurich/Switzerland'
__version__ = '2023071201'
__version__ = '2023071301'

DESCRIPTION = 'Checks the used inode space in percent, default on "/", "/tmp" and "/boot".'

Expand Down Expand Up @@ -105,8 +105,8 @@ def main():
elif inodes_used >= args.WARN:
state = lib.base.get_worst(state, STATE_WARN)
msg = msg[:-2] + ' (WARN), '
except Exception as e:
lib.base.cu('Something seems to be wrong with the input parameter. The error was: {}'.format(e))
except Exception:
lib.base.cu('Something seems to be wrong with the input parameter')

# over and out
lib.base.oao(msg[:-2], state, perfdata, always_ok=args.ALWAYS_OK)
Expand Down
4 changes: 2 additions & 2 deletions check-plugins/matomo-reporting/matomo-reporting
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ from lib.globals import (STATE_CRIT, STATE_OK, # pylint: disable=C0413
STATE_UNKNOWN, STATE_WARN)

__author__ = 'Linuxfabrik GmbH, Zurich/Switzerland'
__version__ = '2023071203'
__version__ = '2023071301'

DESCRIPTION = """This plugin lets you check the most common analytics values from Matomo, for one
or several websites and for any given date and period."""
Expand Down Expand Up @@ -144,7 +144,7 @@ def main():
url = args.URL + ('/' if not args.URL.endswith('/') else '') + 'index.php?method=API.get&idSite={}&period={}&date={}&module=API&token_auth={}&format=json&filter_limit=1'.format(args.IDSITE, args.PERIOD, args.DATE, args.PASSWORD)
result = lib.base.coe(lib.url.fetch_json(url, insecure=args.INSECURE, no_proxy=args.NO_PROXY, timeout=args.TIMEOUT))
if 'result' in result and result['result'] == 'error':
lib.base.cu('{}'.format(result['message']))
lib.base.cu(result['message'])

# init some vars
msg = ''
Expand Down
6 changes: 3 additions & 3 deletions check-plugins/network-io/network-io
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ except ImportError as e:


__author__ = 'Linuxfabrik GmbH, Zurich/Switzerland'
__version__ = '2023071203'
__version__ = '2023071301'

DESCRIPTION = """Checks network IO."""

Expand Down Expand Up @@ -132,8 +132,8 @@ def main():
# get interface data and store it to database
try:
net_io_counters = psutil.net_io_counters(pernic=True, nowrap=True)
except ValueError as e:
lib.base.cu('psutil raised error "{}"'.format(e))
except ValueError:
lib.base.cu('psutil raised an error')

now = lib.time.now()

Expand Down
6 changes: 3 additions & 3 deletions check-plugins/openstack-nova-list/openstack-nova-list
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ except ImportError:


__author__ = 'Linuxfabrik GmbH, Zurich/Switzerland'
__version__ = '2023071202'
__version__ = '2023071301'

DESCRIPTION = """Nova is the OpenStack project that provides a way to provision compute
instances (aka virtual servers).
Expand Down Expand Up @@ -210,11 +210,11 @@ def main():
try:
nova = client.Client(2, session=session.Session(auth=auth)) # NOVA_API_VERSION=2
except Exception as e:
lib.base.cu(e.message)
lib.base.cu('An error occurred while connecting to Nova')
try:
servers = nova.servers.list()
except Exception as e:
lib.base.cu(e.message)
lib.base.cu('An error occurred while getting the server list from Nova')

# init some vars
msg = ''
Expand Down
4 changes: 2 additions & 2 deletions check-plugins/pip-updates/pip-updates
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ from lib.globals import (STATE_CRIT, STATE_OK, # pylint: disable=C0413
STATE_UNKNOWN, STATE_WARN)

__author__ = 'Linuxfabrik GmbH, Zurich/Switzerland'
__version__ = '2023071203'
__version__ = '2023071301'

DESCRIPTION = """Checks if there are outdated Python packages, installed via `pip`."""

Expand Down Expand Up @@ -216,7 +216,7 @@ def main():
try:
packages = json.loads(stdout)
except:
return lib.base.cu('ValueError: No JSON object could be decoded')
return lib.base.cu('Failed to parse JSON.')

# init some vars
if args.VIRTUALENV:
Expand Down
6 changes: 3 additions & 3 deletions check-plugins/restic-snapshots/restic-snapshots
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ from lib.globals import (STATE_CRIT, STATE_OK, # pylint: disable=C0413
STATE_UNKNOWN, STATE_WARN)

__author__ = 'Linuxfabrik GmbH, Zurich/Switzerland'
__version__ = '2023071203'
__version__ = '2023071301'

DESCRIPTION = """Check the age of the newest restic repository snapshot."""

Expand Down Expand Up @@ -247,8 +247,8 @@ def main():

try:
snapshots = json.loads(stdout)
except ValueError as e:
lib.base.cu('ValueError: No JSON object could be decoded')
except ValueError:
lib.base.cu('No JSON object could be decoded.')

# init some vars
msg = ''
Expand Down
6 changes: 3 additions & 3 deletions check-plugins/restic-stats/restic-stats
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import lib.test # pylint: disable=C0413
from lib.globals import STATE_OK, STATE_UNKNOWN # pylint: disable=C0413

__author__ = 'Linuxfabrik GmbH, Zurich/Switzerland'
__version__ = '2023071201'
__version__ = '2023071301'

DESCRIPTION = """Walk multiple snapshots in a repository and accumulate statistics about the data
stored therein. It reports on the number of unique files and their sizes,
Expand Down Expand Up @@ -132,8 +132,8 @@ def main():

try:
stats = json.loads(stdout)
except ValueError as e:
lib.base.cu('ValueError: No JSON object could be decoded')
except ValueError:
lib.base.cu('No JSON object could be decoded.')

# init some vars
state = STATE_OK
Expand Down
6 changes: 3 additions & 3 deletions check-plugins/strongswan-connections/strongswan-connections
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ except ImportError:


__author__ = 'Linuxfabrik GmbH, Zurich/Switzerland'
__version__ = '2023071203'
__version__ = '2023071301'

DESCRIPTION = """This Nagios/Icinga monitoring plugin checks IPSec connection states. It connects
to the vici plugin in libcharon using the Versatile IKE Control Interface (VICI)
Expand Down Expand Up @@ -230,8 +230,8 @@ def main():
s = socket.socket(socket.AF_UNIX)
try:
s.connect(args.SOCKET)
except Exception as e:
lib.base.cu('{}'.format(e))
except Exception:
lib.base.cu('Failed to connect to the VICI Socket.')
session = vici.Session(s)
possible_connection_keys = get_possible_connection_keys(session)
active_connection_keys = get_active_connection_keys(session)
Expand Down
14 changes: 7 additions & 7 deletions check-plugins/xml/xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ from lib.globals import (STATE_OK, STATE_UNKNOWN, # pylint: disable=C0413
__author__ = """Linuxfabrik GmbH, Zurich/Switzerland;
originally written by Simon Wunderlin,
adapted by Dominik Riva, Universitätsspital Basel/Switzerland"""
__version__ = '2023071203'
__version__ = '2023071301'


DESCRIPTION = """This plugin checks for a matching string in a XML document, fetched via http(s).
Expand Down Expand Up @@ -151,8 +151,8 @@ def main():
# analyze data
try:
doc = ET.fromstring(lib.txt.to_bytes(result))
except Exception as e:
lib.base.cu('XML parse error "{}".'.format(e))
except Exception:
lib.base.cu('Failed to parse XML.')

# https://lxml.de/xpathxslt.html
if args.NAMESPACES:
Expand All @@ -164,13 +164,13 @@ def main():
lib.base.cu('Wrong namespace mapping syntax for "{}".'.format(ns))
try:
r = doc.xpath(args.XPATH, namespaces=namespaces)
except Exception as e:
lib.base.cu('XML xpath error "{}".'.format(e))
except Exception:
lib.base.cu('An XML xpath error occurred.')
else:
try:
r = doc.xpath(args.XPATH)
except Exception as e:
lib.base.cu('XML xpath error "{}".'.format(e))
except Exception:
lib.base.cu('An XML xpath error occurred.')

# over and out
if args.EXPECT is None:
Expand Down

0 comments on commit 7fbe46e

Please sign in to comment.