zalando-zmon / zmon-cli

ZMON Command Line Interface
http://zmon.readthedocs.org/en/latest/developer/zmon-cli.html
Other
9 stars 9 forks source link

Zmon client #21

Closed mohabusama closed 8 years ago

mohabusama commented 8 years ago

Note: some of the Zmon client method names are not consistent (update vs create vs add). It is somehow similar to the commands. I was not sure whether we should unify this in this iteration or wait for next upgrade, in order to avoid confusion for users (zmon e push vs zmon e create)

hjacobs commented 8 years ago
  1. I would like to keep __main__.py to use python3 -m zmon_cli (that's how all STUPS tools work)
  2. the output is mangled with "Action" output, i.e. I can't use standard UNIX tools anymore (like awk) --- please use the --output flag to suppress the "Action" output (this is automatically done with OutputFormat)
mohabusama commented 8 years ago

Added custom Output to adjust unified output formatting and error/exception handling. This is done for most commands, and default format varies depending on the command.

hjacobs commented 8 years ago

I get an KeyError now:

 $ python3 -m zmon_cli ent filter type local
 EXCEPTION OCCURRED: 'team'
Traceback (most recent call last):
  File "/usr/lib/python3.5/runpy.py", line 184, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/hjacobs/workspace/zmon-cli/zmon_cli/__main__.py", line 6, in <module>
    main()
  File "/home/hjacobs/workspace/zmon-cli/zmon_cli/main.py", line 10, in main
    cli()
  File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 716, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 696, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 1060, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 1060, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 889, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/click/decorators.py", line 27, in new_func
    return f(get_current_context().obj, *args, **kwargs)
  File "/home/hjacobs/workspace/zmon-cli/zmon_cli/cmds/entity.py", line 57, in filter_entities
    act.echo(entities)
  File "/home/hjacobs/workspace/zmon-cli/zmon_cli/output.py", line 95, in echo
    self.printer(out, self.output)
  File "/home/hjacobs/workspace/zmon-cli/zmon_cli/output.py", line 115, in render_entities
    rows.sort(key=lambda r: (r['id'], r['type'], r['team']))
  File "/home/hjacobs/workspace/zmon-cli/zmon_cli/output.py", line 115, in <lambda>
    rows.sort(key=lambda r: (r['id'], r['type'], r['team']))
KeyError: 'team'
mohabusama commented 8 years ago

Removed team from col output. I assumed all entities has team assigned.

hjacobs commented 8 years ago

@mohabusama you can actually introduce "last_modified" column instead (with nice "..ago" coloring by "print_table")

hjacobs commented 8 years ago

:+1:

mohabusama commented 8 years ago

👍