Execute lq queries using ansible

Hi,

I’m trying to get a report using ansible to execute lq queries and get a report of services monitored in check_mk.

Ansible task:
-
name: ‘Generar Reporte’
become: yes
become_user: ‘{{site_name}}’
shell: “lq ‘GET services\nColumns: host_name description state’”
args:
executable: /bin/bash
register: reporte

Result:

Does anyone has a code sniped I could use to query lq over ansible and want to share it??

Thanks in advance.

not ansible-like, but a snippet that might help:

printf "GET services\nColumns: host_name description state\n" | sudo -u $site_name /omd/sites/${site_name}/bin/unixcat /omd/sites/${site_name}/tmp/run/live

for more see https://checkmk.de/cms_livestatus.html

Olli

It worked!! Thanks a lot for your help!! :smiley: :smiley:

Here is my code:

Task in playbook:
-
name: ‘Generar Reporte’
become: yes
become_user: ‘{{site_name}}’
shell:
cmd: |
printf “GET services\nColumns: host_name description state\n” | sudo -u {{site_name}} /omd/sites/{{site_name}}/bin/unixcat /omd/sites/{{site_name}}/tmp/run/live
args:
executable: /bin/bash
register: reporte

    -
      debug:
        var: reporte.stdout_lines

Inventory with site var:
[check_mk_prod]
your_hostname site_name=your_site_name

I created a repository on git with this project: https://github.com/martinmartossimon/check_mk-ansible-livestatus_query

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.