Skip to content

Commit

Permalink
Merge pull request #206 from bjoernricks/measure-cli-duration
Browse files Browse the repository at this point in the history
Add --duration argument to gvm-cli
  • Loading branch information
bjoernricks authored Sep 9, 2019
2 parents 6bb9080 + ca65e1c commit a5f46ff
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ $ cd gvm-tools && git log
## [Unreleased]

### Added
- Added --duration switch to gvm-cli for command execution measurement [PR 206](https://github.com/greenbone/gvm-tools/pull/206)
- Added --ssh-password switch for ssh connection [PR 140](https://github.com/greenbone/gvm-tools/pull/140)
- Added a new console line interface `gvm-script` for only running GMP and OSP
scripts without opening a python shell [PR 152](https://github.com/greenbone/gvm-tools/pull/152)
Expand Down
19 changes: 16 additions & 3 deletions gvmtools/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import getpass
import logging
import sys
import time

from gvm.errors import GvmError
from gvm.protocols.latest import Osp
Expand Down Expand Up @@ -77,6 +78,11 @@ def main():
action='store_true',
default=False,
)
parser.add_argument(
'--duration',
action='store_true',
help='Measure commmand execution time',
)
parser.add_argument(
'infile', nargs='?', help='File to read XML commands from.'
)
Expand Down Expand Up @@ -131,12 +137,19 @@ def main():
protocol.authenticate(args.gmp_username, args.gmp_password)

try:
if args.duration:
starttime = time.time()

result = protocol.send_command(xml)

if not args.pretty:
print(result)
else:
if args.duration:
duration = time.time() - starttime
print('Elapsed time: {} seconds'.format(duration))
elif args.pretty:
pretty_print(result)
else:
print(result)

except Exception as e: # pylint: disable=broad-except
print(e, file=sys.stderr)
sys.exit(1)
Expand Down

0 comments on commit a5f46ff

Please sign in to comment.