Tech Tip - Auto Generation of Service Groups and other API fun

You are viewing an old version of this page. View the current version. Compare with Current  |   View Page History

This tech tip describes using the sg_autocreate script to automatically create service groups.

The use case for this script is as follows:
You need to generate service groups in the Foundation database so that they show up in the UI.
You have a lot of hosts and services, so using the UI to create these servicegroups is time consuming and tedious.
You have changes to the hosts-service combinations that you want represented in the service groups, and these happen regularly enough that it is desirable to automate the service group creation.

This script will make it possible to create service groups automatically on the commit of the configuration, using data from the existing hosts and services.
While you can run this script at the command line and so integrate it into your existing provisioning systems, we have included an example of calling it from the commit process using the integration module.

The script itself is heavily modular and commented, making it an ideal example for extending to other, similar functions as needed. We welcome your contributions in this regard, as always, and your suggestions for improvement and more use cases.

Here's how to install it and get it going:

Download all the files:

Place the files on the GroundWork server. Put:

in a directory on the GroundWork server where they can be accessed by the nagios user, e.g. /usr/local/groundwork/scripts.
You can lput agent_id in there too, if you like.
Make all the files owned by user nagios

chown nagios.nagios /usr/local/groundwork/scripts/sg_autocreate*

Make sure that the sg_autocreate script is executeable:

chmod +x /usr/local/groundwork/scripts/sg_autocreate

Use the agent_id script to generate a unique id for the creation (and deletion) of the servicegroups you make using this script. You can use any string, as long as it is unique, but this makes a nice example.

agent_id = "59e53d98-a526-11e6-a10c-8170f6c82928"

The quoted string is randomized enough to be used as a unique agent identifier in the foundation database. Edit the file /usr/

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.