Page 2 of 2

Re: API and Hostgroups

Posted: Tue Feb 02, 2021 1:55 pm
by benjaminsmith
Hi Rowan,

Thanks for contributing and sharing your script!

Re: API and Hostgroups

Posted: Thu Feb 18, 2021 5:44 am
by IPOInS
Hi all,

I would say that managing group membership for any of the hosts, hosts groups, services etc. is quite manageable with the API as it stands.
Granted, being able to append to a group or host array is an obvious bonus, rather than having to submit the API request with the complete membership each time. But given you can query the current objects that's easy to do in a script:
E.g. (pseudo-code)
$hostgroup = "MyLiveHosts"
[array]$GroupMembers = retrieve host group $hostgroup
$groupmembers += $newhost
set host group $hostgroup with members $groupmembers

The other issue regarding the almost split-brain group members is something you have to bear in mind (i.e. do you assign the host to a host group or assign the host group to the host?). Although both provide the same end result, querying and managing does mean you need to be consistent with your changes (e.g. always assign a host to a host group). When your script runs it can work as expected; unless you include the method of checking both ways when amending group membership.
mportant question to ask yourself is, what is your ENV "source of truth"?
If your answer is the SN-CMDB (or whatever CMDB you are using), than possibly you do not need to scrap "current memberships" out of XI.
Instead, perhaps it is better to simply "enforce" what the CMDB has on record?
This may save some processing time, if this holds for your scenario.
I agree, this falls into Infrastructure as Code, something that I've been working on for quite some time with other systems and one I'm starting to put into place with Nagios XI.
Using PowerShell I'm able to manage host, service, groups, commands, etc. pretty much everything that is available from the API (including any of the under-the-hood core commands such as scheduled downtimes and comments, disabling checks etc.).
Regarding the use of a CSV or CMDB, in our case each object can be defined in XML (much like defining an ARM template or Terraform configuration) and then be applied to the Nagios XI server. Thus this becomes the truth. I'm not completely there yet, somethings still in development, but the XML method works fine, it's all doable with what's available within Nagios XI right now.
The other plan in development is to handle some bits dynamically, such as assigning checks on the fly based on server tag information or the detected OS or whether it has a particular port open or application installed.

Re: API and Hostgroups

Posted: Thu Feb 18, 2021 5:05 pm
by benjaminsmith
@IPOInS Thanks!.

For those of us on the support team here, we don't always interact with the product in the same ways as you, the customer, so we really appreciate the feedback and suggestions.

--Benjamin