Page 1 of 1
Adding Hosts by API vs Bash Script/Template.cfg
Posted: Fri May 05, 2017 10:10 am
by nagwindmon
I'm taking over our Nagios set up and changing the way we were adding Hosts by utilizing API instead of using script, all seems like working as design however there are some differences in hostname.cfg files (please see attached). Is it due to upgrade to a new version XI offering API options or may missing something constructing API call?
curl -XPOST "
http://xxxxxx/nagiosxi/api/v1/config/ho ... r&pretty=1" -d "host_name=CVTK4162909&use=xiwizard_windowsdesktop_host&alias=CVT&address=CVTK4162909&hostgroups=DRT_CVT,MCY-006-EST&check_command=mst_check_snmp_name&max_check_attempts=25&check_interval=60&retry_interval=60&check_period=24x7¬ification_interval=60¬ification_period=24x7&force=1"
Thanks!
Re: Adding Hosts by API vs Bash Script/Template.cfg
Posted: Fri May 05, 2017 10:38 am
by dwhitfield
Could you clarify how you want it to look from the API?
I see the following two are missing from the API
Code: Select all
icon_image windowsxp.png
statusmap_image windowsxp.png
However, those aren't in your API call. The xiwizard is also not there, but if you aren't using a wizard, I'm not sure why you would want that there.
Also, xi_timeperiod_24x7 could be used in the API if that's how you'd prefer it to look. As long as those two timeperiods are defined the same, it won't matter which you use.
Re: Adding Hosts by API vs Bash Script/Template.cfg
Posted: Fri May 05, 2017 10:54 am
by nagwindmon
Code: Select all
icon_image windowsxp.png
statusmap_image windowsxp.png
What are those two represent, what they use for?
Also there are few a (!) marks showing next to command name but none in .cfg file generated by API?
Here the command itself:
define command {
command_name mst_check_snmp_name
command_line $USER1$/check_snmp -H $HOSTADDRESS$ -o sysName.0 -C public -P 2c -l "name" -r $HOSTNAME$
}
Re: Adding Hosts by API vs Bash Script/Template.cfg
Posted: Fri May 05, 2017 11:41 am
by lmiltchev
The icon_image and statusmap_image are not required, but you can add them if you wish by adding this to your API command:
Code: Select all
&icon_image=windowsxp.png&statusmap_image=windowsxp.png
Here's an explanation on what they do:
Host - icon image
This variable is used to define the name of a GIF, PNG, or JPG image that should be associated with this host. This image will be displayed in the various places in the CGIs. The image will look best if it is 40x40 pixels in size. Images for hosts are assumed to be in the logos/ subdirectory in your HTML images directory (i.e. /usr/local/nagios/share/images/logos).
Parameter name: icon_image
Required: no
Host - statusmap image
This variable is used to define the name of an image that should be associated with this host in the statusmap CGI. You can specify a JPEG, PNG, and GIF image if you want, although I would strongly suggest using a GD2 format image, as other image formats will result in a lot of wasted CPU time when the statusmap image is generated.
GD2 images can be created from PNG images by using the pngtogd2 utility supplied with Thomas Boutell's gd library . The GD2 images should be created in uncompressed format in order to minimize CPU load when the statusmap CGI is generating the network map image.
The image will look best if it is 40x40 pixels in size. You can leave these option blank if you are not using the statusmap CGI. Images for hosts are assumed to be in the logos/ subdirectory in your HTML images directory (i.e. /usr/local/nagios/share/images/logos).
Parameter name: statusmap_image
Required: no
Here's an example of the same icon in the GUI (under Host Detail & Status Map):
example01.PNG
example02.PNG
As far as the extra "!" signs in the command, these are delimiters added by the CCM. You don't actually need them, unless they separate arguments. They won't hurt anything, either (if they are present). The API command won't be adding these at the end.
Hope this helps.
Re: Adding Hosts by API vs Bash Script/Template.cfg
Posted: Fri May 05, 2017 2:39 pm
by nagwindmon
Yes it did, thanks for detail explanation! I think I'm good for now.
You can lock this thread if you like.