Livestatus query grouping services

hi all,

its possible to group the services for a host e.g.:

OMD[mysite]:~$ lq
GET services
Columns: host_name description state
Filter: state = 2

myserver123;Filesystem D:/;2
myserver123;Filesystem K:/;2
myserver123;Filesystem Y:/;2

to 

myserver123;Filesystem D:/;2;Filesystem K:/;2;Filesystem Y:/;2

Thanks in advance

Its possible to have multiple Tables like GET hosts and GET services ?

Hi @neeloj,
not in livestatus but if you are using it on the CLI, you can CLI tools to achieve that.
I.e.
take the result of your first query and pipe it to:

| tr , '\n' 
1 Like

Thank you @gstolz yes I work on CLI

thats good idea I’ll test it now :slight_smile:
so it will be liek below ?
lq "GET hosts\nColumns: name address" | tr , '\n' lq "GET services"

it would look more like

lq "GET services\nColumns: host_name description state\nFilter: state = 2\nFilter: host_name = myhostname" | tr , '\n'

beware, you might need additional filters for hostname or service description

Or did you want to get a list of…?

host_a, <list of services of host a>
host_b, <list of services of host b>
…

1 Like

thank you Im so far like your command.
this is not a problem:

lq "GET services\nColumns: host_name description state\nFilter: state = 2\nFilter: host_name = myhostname" 

my problem is to understand the tr , '\n' can I use after that e.g GET contacts ?

I want to get the contact email address from each folder.
every folder have own admin

and I have to know how can I join the lq tables

thank you again @gstolz

wait, so it’s not just about services?
Can you create some mock-up output of what you need or explain the problem you are trying to solve? Maybe there is a better solution that livestatus queries.

1 Like

@gstolz you are right.

Here what I want to achieve:

FolderX have a contact_group
HostsX have critical services
UserX have the same contact_group like the FolderX and email address

I want to get all critical services with the email address of the user.

Thats what I want to achieve

Hi @neeloj,
ok, I think you will need multiple queries to do that, simply because the “services” table in livestatus holds the contact_groups and contacts, but not the contact mail address. The mail address is only available in the “contacts” table. As far as I know and Livestatus command reference seems to support that, livestatus query language, doesn’t support SQL style joins. So you have to query your services first and then combine the output with a query against the contacts table. I would suggest python for this. There are examples and code at ~/share/doc/check_mk/livestatus within each checkmk installation

1 Like

Yes you are right, and I can output them as python list.

thats so pity!

I’ll check here

Good idea thanks!

thank you so much @gstolz

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed. Contact an admin if you think this should be re-opened.