Skip to content

Commit 5f20b60

Browse files
authored
Merge pull request #4 from dnmvisser/dv_fix_remainder_opts
Fix logic for extra arguments
2 parents da454ef + 50fa198 commit 5f20b60

File tree

2 files changed

+36
-14
lines changed

2 files changed

+36
-14
lines changed

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,15 @@ usage: nagios-testssl.py [-h] --uri URI --testssl TESTSSL
2525
[--ignore-ids IGNORE_IDS]
2626
[--critical {LOW,MEDIUM,HIGH,CRITICAL}]
2727
[--warning {LOW,MEDIUM,HIGH,CRITICAL}]
28+
...
2829
29-
Check output of testssl.sh
30+
Test support of TLS/SSL ciphers, protocols as well as cryptographic flaws and
31+
much more. This is a wrapper around testssl.sh
32+
(https://github.com/drwetter/testssl.sh
33+
34+
positional arguments:
35+
trailing_args Provide extra arguments to testssl.sh at the end,
36+
separated by '--'
3037
3138
optional arguments:
3239
-h, --help show this help message and exit
@@ -40,6 +47,7 @@ optional arguments:
4047
--warning {LOW,MEDIUM,HIGH,CRITICAL}
4148
Findings of this severity level trigger a WARNING
4249
```
50+
4351
# Examples
4452

4553
Checking a URI with default severity levels:
@@ -76,3 +84,13 @@ vagrant@buster:~$ ./nagios-testssl.py --testssl /opt/testssl/testssl.sh \
7684
--uri https://login.geant.org --critical HIGH --warning MEDIUM
7785
OK: No issues found for https://login.geant.org with severity MEDIUM or higher.
7886
```
87+
88+
As the previous example, but with extra options for testssl.sh. These need to
89+
be passed in at the end and separated by `--`:
90+
91+
```
92+
vagrant@buster:~$ ./nagios-testssl.py --testssl /opt/testssl/testssl.sh \
93+
--uri https://login.geant.org --critical HIGH --warning MEDIUM \
94+
-- --phone-out --sneaky --full
95+
OK: No issues found for https://login.geant.org with severity MEDIUM or higher.
96+
```

nagios-testssl.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ def nagios_exit(message, code):
2020
'CRITICAL': 4,
2121
}
2222
try:
23-
parser = argparse.ArgumentParser(description='Check output of testssl.sh')
23+
parser = argparse.ArgumentParser(description='Test support of TLS/SSL ciphers, '
24+
'protocols as well as cryptographic flaws and much more. This is a wrapper '
25+
'around testssl.sh (https://github.com/drwetter/testssl.sh')
2426
parser.add_argument('--uri', help='host|host:port|URL|URL:port.'
2527
'Port 443 is default, URL can only contain HTTPS protocol', required=True)
2628
parser.add_argument('--testssl', help='Path to the testssl.sh script', required=True)
@@ -29,12 +31,13 @@ def nagios_exit(message, code):
2931
choices=severities.keys(), default='CRITICAL')
3032
parser.add_argument('--warning', help='Findings of this severity level trigger a WARNING',
3133
choices=severities.keys(), default='HIGH')
32-
# FIXME this is unreliable
33-
#parser.add_argument('trailing_args', nargs=argparse.REMAINDER)
34+
parser.add_argument('trailing_args', help='Provide extra arguments to testssl.sh at the end, '
35+
'separated by \'--\'', nargs=argparse.REMAINDER)
3436
args = parser.parse_args()
3537

3638
if severities[args.critical] < severities[args.warning]:
37-
parser.error('The severity level to raise a WARNING can not be higher than the level to raise a CRITICAL')
39+
parser.error('The severity level to raise a WARNING can not be higher'
40+
'than the level to raise a CRITICAL')
3841

3942
if urlparse(args.uri).scheme != 'https':
4043
parser.error('The scheme of the URI must be \'https\'')
@@ -44,8 +47,7 @@ def nagios_exit(message, code):
4447
critical = args.critical
4548
warning = args.warning
4649
ignore_ids = args.ignore_ids.split(',')
47-
# trailing_args = args.trailing_args
48-
# pprint(args)
50+
trailing_args = args.trailing_args
4951

5052

5153
# Possible nagios statuses
@@ -62,17 +64,19 @@ def nagios_exit(message, code):
6264
# Set command and arguments
6365
subproc_args = [
6466
testssl,
65-
# '--fast',
6667
'--jsonfile-pretty',
6768
temp_path,
68-
uri
6969
]
7070

71-
# FIXME this is unreliable
72-
# Inject this script's trailing command line arguments before the 'uri' part of
73-
# the testssl.sh command.
74-
# for extra in trailing_args:
75-
# subproc_args.insert(3, extra)
71+
# Remove '--' separator from the trailing arguments
72+
trailing_args.remove('--')
73+
74+
# Add the trailing arguments
75+
subproc_args.extend(trailing_args)
76+
77+
# Add the URI as the last argument
78+
subproc_args.extend([uri])
79+
7680

7781
# Run it
7882
proc = subprocess.run(subproc_args, stdout=subprocess.PIPE)

0 commit comments

Comments
 (0)