Skip to content

Commit a1a51ea

Browse files
committed
fix(icinga-topflap-services): prevent stacktrace when required parameters are empty
1 parent 33bba33 commit a1a51ea

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

check-plugins/icinga-topflap-services/icinga-topflap-services

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ from lib.globals import (STATE_CRIT, STATE_OK, # pylint: disable=C0413
2929
STATE_UNKNOWN, STATE_WARN)
3030

3131
__author__ = 'Linuxfabrik GmbH, Zurich/Switzerland'
32-
__version__ = '2025071001'
32+
__version__ = '2025091001'
3333

3434
DESCRIPTION = """This check plugin counts the number of state changes per service within a
3535
given lookback interval. This makes it possible to detect fast flapping services.
@@ -187,10 +187,14 @@ def main():
187187
except SystemExit:
188188
sys.exit(STATE_UNKNOWN)
189189

190-
if not args.USERNAME or not args.PASSWORD or not args.URL:
191-
lib.base.cu('`--url`, `--username` and `--password` are required parameters. You can '
192-
'also provide a password file for IcingaWeb to read "url", "user" or '
193-
'"password" from.')
190+
have_creds = args.USERNAME and args.PASSWORD and args.URL
191+
have_pwfile = args.PWFILE
192+
if not (have_creds or have_pwfile):
193+
lib.base.cu(
194+
'The three parameters `--url`, `--username` and `--password` are required. ' \
195+
'Alternatively, you can provide a password file for IcingaWeb to read ' \
196+
'the "url", "user" or "password" from, using `--pwfile`.'
197+
)
194198

195199
# if given, read password INI-file, but cmdline takes precedence
196200
config = configparser.ConfigParser()
@@ -209,6 +213,13 @@ def main():
209213
print(e)
210214
sys.exit(STATE_UNKNOWN)
211215

216+
have_creds = args.USERNAME and args.PASSWORD and args.URL
217+
if not have_creds:
218+
lib.base.cu(
219+
'Either the username, password or URL is not specified' + \
220+
f' in `{args.PWFILE}`.' if args.PWFILE else '.'
221+
)
222+
212223
# init some vars
213224
msg = ''
214225
state = STATE_OK

0 commit comments

Comments
 (0)