Export Hostnames

Hi folks. I’m trying to get an export of all hosts’ hostnames/ip addresses and (if possible) agent/no-agent status (plus some other information). I though that there was a way to export all hosts, but from the main overview page that only exports the Alias or Hostname of the hosts, not the actual hostnames or IPs (ie: Firewall-1 vs 192.168.1.1 or firewall.company.com). For the life of me I can’t find this in the GUI, and I’m not that familiar with CheckMK to find it in a backend database. The closest I could find is a hosts.mk file in /omd/sites/monitor/etc/check_mk/conf.d/wato/firewalls/hosts.mk

This looks like a dump of python data, but isn’t super parsable. I was really hoping there was a export or SQL that I could run to get a CSV of something like:

Hostname, Alias, ip address, agent type, folder

Or even just Hostname and ip address.

Is there a way to get this information out of the system? I assume there must be and I just haven’t found it yet.

Info: Check_mk 1.2.8p20 (yea, I know it’s old but it’s what I’ve been given to work with right now).

Thanks.

The “Host” that you add into checkmk, as far as checkmk is concerned is “the host”. Any information that requires a client side check to retrieve information is different. Including, for example, a call to the OS hostname command.

So, names are funny things. The hostname as defined by the OS doesn’t need to be fully qualified, nor does it have to match what is in checkmk, nor does it have to match was is contained in any name server (DNS). In other words, there are many views and many “opinions” on what a valid name actually is depending on viewpoint.

You’d have the same sort of ambiguity from any kind of inspection and/or monitoring tool btw.

Fair point . I am looking at the server and right now I have all the hostnames as names “firewall-yvr-1” that don’t resolve (using the host command) on the server, vs the ipv4 address. Looks like in WATO there are three “names” - hostnane, alias, and ipv4 address. Either way I’d like a list of all of them for all hosts - that’s sort of the end goal.

I’m trying via the webapi but right now I just get “the wato api is only available for automation users” :frowning:

$curl -u "myuser:password" 'http://site.com/monitoring/check_mk/webapi.py?action=get_all_hosts&_username=automation&_secret=<secret>'
{"result": "The WATO API is only available for automation users", "result_code": 1}%           

Not really sure what’s going on there. The automation user is set to access by automation and has the same secret set. I’ve tried running it on the server and remotely.

Any ideas for that one? It seems like the web-api is the way to go and get this stuff, but I can’t even get past the first step here :frowning:

Add the parameter &output_format=json to your url

No, it’s giving that output for anything it looks like:

 curl -u "user:pass" 'http://site.com/monitoring/check_mk/webapi.py?action=get_all_hosts&_username=automation&_secret=secret&output_format=json'          ✔ 
{"result": "The WATO API is only available for automation users", "result_code": 1}%

With an automation user you shouldn’t need the -u user:pass, maybe that’s the issue?

The site has htpasswd protection, so that’s needed or I get a 401 unauthorized error.

This is what I get:

curl -s "https://example.com/monitor/check_mk/webapi.py?action=get_all_hosts&_userna
me=automation&_secret=secret&output_format=json" | python3 -mjson.tool 
{
    "result": {
        "host1": {
            "attributes": {
                "tag_agent": "special-agents",
                "snmp_community": "noneyabusiness",
                "tag_snmp_ds": "snmp-v2",
                "labels": {
                    "sk_hw": "dell"
                },
                "meta_data": {
                    "created_at": 1596119534.0,
                    "created_by": "cjcox"
                },
                "tag_skopos_env": "sk_network"
            },
            "hostname": "host1",
            "path": ""
        },
        "dmssql1": {

Yup, as far as I can see that should be all that’s needed, but the system doesn’t seem to think that the user is allowed to do the automation. There’s only one other post on the topic but it doesn’t have any answers.

Here’s my user setup.

Hi,
a very quick solution for your problem:

  1. Create a view in the web GUI with all your data e.g. hostname, alias, ip …
  2. Open the view
  3. Click the icon “URL to this frame” at the bottom of your view
  4. Add “&output_format=csv_export” to the URL

Karl

1 Like

Perfect - thank you!

hello

maybe another solution via command line:
lq “GET hosts\nColumns: name”
lq “GET hosts\nColumns: name alias parents”
lq “GET hosts\nColumns: name address alias parents”

Greetings
JP

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