Git Product home page Git Product logo

ansible-graylog-modules's People

Contributors

hulkk avatar matthgyver avatar shortstack avatar ziehmon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ansible-graylog-modules's Issues

graylog_* error handling issue

I believe I have identified an issue in the get_token function of the modules that will result in a KeyError instead of the desired Ansible module failure if the Graylog endpoint does not exist or is down.

- name: base_graylog_config | get inputs
  graylog_input:
    endpoint: localhost:9000
    graylog_user: admin
    graylog_password: "{{ graylog_admin_pass }}"
    action: list
    allow_http: true
  register: inputs

Error:

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: KeyError: 'body'
    fatal: [test-molecule-graylog]: FAILED! => {"changed": false, "module_stderr": "Shared connection to 10.64.34.237 closed.\r\n", "module_stdout": "Traceback (most recent call last):\r\n  File \"/home/molecule/.ansible/tmp/ansible-tmp-1581105797.887236-245989639182613/AnsiballZ_graylog_input.py\", line 102, in <module>\r\n    _ansiballz_main()\r\n  File \"/home/molecule/.ansible/tmp/ansible-tmp-1581105797.887236-245989639182613/AnsiballZ_graylog_input.py\", line 94, in _ansiballz_main\r\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n  File \"/home/molecule/.ansible/tmp/ansible-tmp-1581105797.887236-245989639182613/AnsiballZ_graylog_input.py\", line 40, in invoke_module\r\n    runpy.run_module(mod_name='ansible.modules.graylog_input', init_globals=None, run_name='__main__', alter_sys=True)\r\n  File \"/usr/lib64/python2.7/runpy.py\", line 176, in run_module\r\n    fname, loader, pkg_name)\r\n  File \"/usr/lib64/python2.7/runpy.py\", line 82, in _run_module_code\r\n    mod_name, mod_fname, mod_loader, pkg_name)\r\n  File \"/usr/lib64/python2.7/runpy.py\", line 72, in _run_code\r\n    exec code in run_globals\r\n  File \"/tmp/ansible_graylog_input_payload_ASMJXC/ansible_graylog_input_payload.zip/ansible/modules/graylog_input.py\", line 199, in <module>\r\n  File \"/tmp/ansible_graylog_input_payload_ASMJXC/ansible_graylog_input_payload.zip/ansible/modules/graylog_input.py\", line 173, in main\r\n  File \"/tmp/ansible_graylog_input_payload_ASMJXC/ansible_graylog_input_payload.zip/ansible/modules/graylog_input.py\", line 132, in get_token\r\nKeyError: 'body'\r\n", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

This is caused by this section of error handling here which assumes that it always receives an application error (and not some network level issue):

https://github.com/ReconInfoSec/ansible-graylog-modules/blob/master/library/graylog_collector_configurations.py#L259

This could be fixed by adding something like this:

if 'urlopen error' in info['msg']:
        module.fail_json(msg="Fail: %s" % ("Status: Connection refused"))
elif info['status'] != 200:
        module.fail_json(msg="Fail: %s" % ("Status: " + str(info['msg']) + ", Message: " + str(info['body'])))
 fatal: [test-molecule-graylog]: FAILED! => {"changed": false, "msg": "Fail: Status: Connection refused"}

Which would be much clearer.

I'd be happy to submit a PR for this if wanted.

Bug in Graylog_streams.py for Graylog 3.x

Example Task to reproduce:

    - name: Create stream
      graylog_streams:
        action: create
        endpoint: "{{ endpoint }}"
        graylog_user: "{{ graylog_user }}"
        graylog_password: "{{ graylog_password }}"
        title: "{{ stream_name }}"
        description: "{{ stream_desc }}"
        matching_type: "AND"
        remove_matches_from_default_stream: True
        rules:
          - {"field":"message","type":1,"value":"test_stream rule","inverted": false,"description":"test_stream rule"}

The full traceback is:
Traceback (most recent call last):
File "/root/.ansible/tmp/ansible-tmp-1558120641.39-158998988338179/AnsiballZ_graylog_streams.py", line 113, in
_ansiballz_main()
File "/root/.ansible/tmp/ansible-tmp-1558120641.39-158998988338179/AnsiballZ_graylog_streams.py", line 105, in _ansiballz_main
invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
File "/root/.ansible/tmp/ansible-tmp-1558120641.39-158998988338179/AnsiballZ_graylog_streams.py", line 48, in invoke_module
imp.load_module('main', mod, module, MOD_DESC)
File "/tmp/ansible_graylog_streams_payload_N_qF4Q/main.py", line 739, in
File "/tmp/ansible_graylog_streams_payload_N_qF4Q/main.py", line 700, in main
File "/tmp/ansible_graylog_streams_payload_N_qF4Q/main.py", line 605, in default_index_set
File "/usr/lib/python2.7/json/init.py", line 339, in loads
return _default_decoder.decode(s)
File "/usr/lib/python2.7/json/decoder.py", line 364, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python2.7/json/decoder.py", line 382, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

fatal: [localhost]: FAILED! => {
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"/root/.ansible/tmp/ansible-tmp-1558120641.39-158998988338179/AnsiballZ_graylog_streams.py\", line 113, in <module>\n    _ansiballz_main()\n  File \"/root/.ansible/tmp/ansible-tmp-1558120641.39-158998988338179/AnsiballZ_graylog_streams.py\", line 105, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/root/.ansible/tmp/ansible-tmp-1558120641.39-158998988338179/AnsiballZ_graylog_streams.py\", line 48, in invoke_module\n    imp.load_module('__main__', mod, module, MOD_DESC)\n  File \"/tmp/ansible_graylog_streams_payload_N_qF4Q/__main__.py\", line 739, in <module>\n  File \"/tmp/ansible_graylog_streams_payload_N_qF4Q/__main__.py\", line 700, in main\n  File \"/tmp/ansible_graylog_streams_payload_N_qF4Q/__main__.py\", line 605, in default_index_set\n  File \"/usr/lib/python2.7/json/__init__.py\", line 339, in loads\n    return _default_decoder.decode(s)\n  File \"/usr/lib/python2.7/json/decoder.py\", line 364, in decode\n    obj, end = self.raw_decode(s, idx=_w(s, 0).end())\n  File \"/usr/lib/python2.7/json/decoder.py\", line 382, in raw_decode\n    raise ValueError(\"No JSON object could be decoded\")\nValueError: No JSON object could be decoded\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}

Python error - The error was: KeyError: 'body'

Hi,

I have this error:

root@DESKTOP-O90K5P8:~/ansible-graylog-lib# ansible-playbook -i /root/playbooks/inventory list_input.yml


PLAY [localhost] ****************************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] **********************************************************************************************************************************************************************************************************************
ok: [localhost]

TASK [Display all inputs] *******************************************************************************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: KeyError: 'body'
fatal: [localhost]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"/root/.ansible/tmp/ansible-tmp-1646224677.9164226-42195067791243/AnsiballZ_graylog_input.py\", line 102, in <module>\n    _ansiballz_main()\n  File \"/root/.ansible/tmp/ansible-tmp-1646224677.9164226-42195067791243/AnsiballZ_graylog_input.py\", line 94, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/root/.ansible/tmp/ansible-tmp-1646224677.9164226-42195067791243/AnsiballZ_graylog_input.py\", line 40, in invoke_module\n    runpy.run_module(mod_name='ansible.modules.graylog_input', init_globals=None, run_name='__main__', alter_sys=True)\n  File \"/usr/lib/python3.8/runpy.py\", line 207, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib/python3.8/runpy.py\", line 97, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/usr/lib/python3.8/runpy.py\", line 87, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_graylog_input_payload_qewhkv0l/ansible_graylog_input_payload.zip/ansible/modules/graylog_input.py\", line 199, in <module>\n  File \"/tmp/ansible_graylog_input_payload_qewhkv0l/ansible_graylog_input_payload.zip/ansible/modules/graylog_input.py\", line 173, in main\n  File \"/tmp/ansible_graylog_input_payload_qewhkv0l/ansible_graylog_input_payload.zip/ansible/modules/graylog_input.py\", line 132, in get_token\nKeyError: 'body'\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

PLAY RECAP **********************************************************************************************************************************************************************************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

With this playbook test:

root@DESKTOP-O90K5P8:~/ansible-graylog-lib# cat list_input.yml
---
- hosts: localhost
  connection: local
  vars:
    - endpoint: "http://localhost:9000/api"
    - graylog_user: admin
    - graylog_password: admin
  tasks:
    - name: Display all inputs
      graylog_input:
        endpoint: "{{ endpoint }}"
        graylog_user: "{{ graylog_user }}"
        graylog_password: "{{ graylog_password }}"
        allow_http: "true"
        validate_certs: "false"
        action: "list"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.