Issue importing service templates

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
gzaloprgm
Posts: 33
Joined: Mon Aug 06, 2018 8:46 am
Contact:

Issue importing service templates

Post by gzaloprgm »

Hi. I've found a bug regarding importing service templates. When importing service templates that have no "Check interval", "Retry interval" or "Max check attempts" defined, that value gets set to 0 instead of staying blank.

For instance, after importing

Code: Select all

define service {
    name                            bugged-service-template
    use                             generic-service
    register                        0
}
Image

This is a regression, it used to work perfectly in older versions. The cause is wrong default values in tbl_servicetemplate table of nagiosql:

Code: Select all

MariaDB [nagiosql]> describe tbl_servicetemplate;
+------------------------------+---------------------+------+-----+---------------------+-----------------------------+
| Field                        | Type                | Null | Key | Default             | Extra                       |
+------------------------------+---------------------+------+-----+---------------------+-----------------------------+
| id                           | int(10) unsigned    | NO   | PRI | NULL                | auto_increment              |
| template_name                | varchar(255)        | NO   | MUL |                     |                             |
| host_name                    | tinyint(3) unsigned | NO   |     | 0                   |                             |
| host_name_tploptions         | tinyint(3) unsigned | NO   |     | 2                   |                             |
| hostgroup_name               | tinyint(3) unsigned | NO   |     | 0                   |                             |
| hostgroup_name_tploptions    | tinyint(3) unsigned | NO   |     | 2                   |                             |
| service_description          | varchar(255)        | NO   |     |                     |                             |
| display_name                 | varchar(255)        | NO   |     |                     |                             |
| servicegroups                | tinyint(3) unsigned | NO   |     | 0                   |                             |
| servicegroups_tploptions     | tinyint(3) unsigned | NO   |     | 2                   |                             |
| use_template                 | tinyint(3) unsigned | NO   |     | 0                   |                             |
| use_template_tploptions      | tinyint(3) unsigned | NO   |     | 2                   |                             |
| check_command                | text                | YES  |     | NULL                |                             |
| is_volatile                  | tinyint(3) unsigned | NO   |     | 2                   |                             |
| initial_state                | varchar(20)         | NO   |     |                     |                             | 
| max_check_attempts           | int(11)             | YES  |     | 0                   |                             | !!! INCORRECT
| check_interval               | int(11)             | YES  |     | 0                   |                             | !!! INCORRECT
| retry_interval               | int(11)             | YES  |     | 0                   |                             | !!! INCORRECT
...
A simple workaround would be to execute

Code: Select all

ALTER TABLE tbl_servicetemplate ALTER max_check_attempts SET DEFAULT NULL;
ALTER TABLE tbl_servicetemplate ALTER check_interval SET DEFAULT NULL;
ALTER TABLE tbl_servicetemplate ALTER retry_interval SET DEFAULT NULL;
Tested using the provided XI 5.5.7 ovf/ova.
Thanks, Gonzalo
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: Issue importing service templates

Post by ssax »

I think you're right about the solution but this will need to be submitted to the developers as a bug to make sure that changing them doesn't have a bigger impact. It could be done through the import script or in the DB.

When you add them through the web UI you get this:

Code: Select all

max_check_attempts: NULL
check_interval: NULL
retry_interval: NULL
What specific version of XI are you running? You can grab it from the bottom left hand side of the web interface.

Thank yiou
gzaloprgm
Posts: 33
Joined: Mon Aug 06, 2018 8:46 am
Contact:

Re: Issue importing service templates

Post by gzaloprgm »

Hi.
I was using 5.5.7 but the issue happens with 5.5.8 as well.
I think that the bug is caused by this lines of xi-5.5.8/nagiosxi/subcomponents/ccm/db/schema.sql (which is imported to the database on install)

Code: Select all

CREATE TABLE IF NOT EXISTS `tbl_servicetemplate` (
...
  `max_check_attempts` int(11) default NULL default '0',
  `check_interval` int(11) default NULL default '0',
  `retry_interval` int(11) default NULL default '0',
That double "default" value weems odd. As stated before, the default value of those fields should be NULL instead of 0, otherwise stuff may break when importing multiple default templates that don't have some of those 3 fields defined.

Thanks, Gonzalo
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: Issue importing service templates

Post by ssax »

Yes, good catch, I think you're right about that as well. I'll reach out to the devs on this again to see what it should be.
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: Issue importing service templates

Post by ssax »

It should be these:

Code: Select all

`max_check_attempts` int(11) DEFAULT NULL,
`check_interval` int(11) DEFAULT NULL,
`retry_interval` int(11) DEFAULT NULL,
So your workaround would be the fix:

Code: Select all

ALTER TABLE tbl_servicetemplate ALTER max_check_attempts SET DEFAULT NULL;
ALTER TABLE tbl_servicetemplate ALTER check_interval SET DEFAULT NULL;
ALTER TABLE tbl_servicetemplate ALTER retry_interval SET DEFAULT NULL;
I've submitted it as a bug for the developers to fix.

NEW TASK ID 13954 created - Nagios XI Bug Report: XI - nagiosql schema script bug for max_check_attempts, check_interval, retry_interval
Locked