Page 1 of 1

Host or Service using Manage Free Variables

Posted: Fri Aug 14, 2020 3:51 pm
by JosephH
Is there a limitation on how many free variables can be set for a host/service config from CCM Misc Settings/Manage Free Variables?
Can I use Nagios API to get the defined free variables for host or service?
Thanks
Joseph

Re: Host or Service using Manage Free Variables

Posted: Mon Aug 17, 2020 2:28 pm
by benjaminsmith
HI Joseph,
Can I use Nagios API to get the defined free variables for host or service?
If you add the customvars=1 value to the API call for returning host data it will include any custom variables. Take a look at the API documentation by going to Help > API Docs > Objects Reference for sample commands and examples. Let me know if that would work for you.

Also, I looked over the database info, and I don't believe there's any defined limitation on free variables, what kind of numbers are you thinking about?

Ben

Re: Host or Service using Manage Free Variables

Posted: Tue Aug 18, 2020 10:22 am
by JosephH
Hi Ben,
Yes, I can get the free variable by adding customvars=1 to the API.
As for the number of free variables, currently not many, maybe around 10.
On the other hand, can I set the free variables through API?

Thank you very much!
Joseph

Re: Host or Service using Manage Free Variables

Posted: Wed Aug 19, 2020 10:31 am
by mbellerue
Yes, you can modify or create new free variables via the API. Here is an example of creating a new free variable. If this free variable had existed, it would have updated the free variable.

Code: Select all

[root@nagiosxi1 ~]# curl -XGET "http://192.168.14.11/nagiosxi/api/v1/config/host?apikey=9uRkM667AHJQMjCKmVaHpnTjS7l0tYoVtffvEkWbiV04eSODNehsEq6tRqNEJbAc&host_name=Server%20-%20NagiosLS1&pretty=1"
[
    {
        "host_name": "Server - NagiosLS1",
        "use": [
            "FD NCPA Any OS",
            "linux-server"
        ],
        "alias": "Demo Log Server 1",
        "address": "192.168.14.12",
        "hostgroups": [
            "FD Tier 1 NCPA Any OS",
            "FD Tier 1 NCPA Linux"
        ],
        "notes": "41.884919, -87.653877",
        "_ncpa_token": "5ea1e0c382bbe3.26670467",
        "register": "1"
    }
]
[root@nagiosxi1 ~]# curl -XPUT "http://192.168.14.11/nagiosxi/api/v1/config/host/Server%20-%20NagiosLs1?apikey=9uRkM667AHJQMjCKmVaHpnTjS7l0tYoVtffvEkWbiV04eSODNehsEq6tRqNEJbAc&pretty=1&_newvar=MyNewVariable&applyconfig=1"
{
    "success": "Updated Server - NagiosLs1 in the system. Config applied, Nagios Core was restarted."
}
[root@nagiosxi1 ~]# curl -XGET "http://192.168.14.11/nagiosxi/api/v1/config/host?apikey=9uRkM667AHJQMjCKmVaHpnTjS7l0tYoVtffvEkWbiV04eSODNehsEq6tRqNEJbAc&host_name=Server%20-%20NagiosLS1&pretty=1"
[
    {
        "host_name": "Server - NagiosLs1",
        "use": [
            "FD NCPA Any OS",
            "linux-server"
        ],
        "alias": "Demo Log Server 1",
        "address": "192.168.14.12",
        "hostgroups": [
            "FD Tier 1 NCPA Any OS",
            "FD Tier 1 NCPA Linux"
        ],
        "notes": "41.884919, -87.653877",
        "_ncpa_token": "5ea1e0c382bbe3.26670467",
        "_newvar": "MyNewVariable",
        "register": "1"
    }
]
First I get the host configuration to show that _newvar does not exist. Then I use he put command to create and set _newvar. And finally I get the host configuration again to show that _newvar exists and is set to what I wanted.

There is a lot of information to parse there. Definitely give us a shout if you need any additional help with this.