Page 1 of 2

Scheduled downtime duration field

Posted: Fri Aug 31, 2018 6:16 am
by CBoekhuis
Hi ,
we encounter a problem with the duration calculation of the recurring downtime in version 5.5.2 and 5.5.3.
When making a downtime schedule for a host and we select a start & end time greater than 10 hours the duration field will show "9h 6m 7s" instead of 10 or higher.
We run on CentOS release 6.8 (Final).

Regards,
Christian

Re: Scheduled downtime duration field

Posted: Fri Aug 31, 2018 9:47 am
by lmiltchev
Schedule a recurring downtime for a host by setting up Start TIme to be 10-15 min in the future, and Duration = 660 (660 min = 11 hours). Click Submit Schedule. Next, run the following command from the CLI:

Code: Select all

php /usr/local/nagiosxi/cron/recurring_downtime.php
Show the screenshots of the Recurring Downtime and the Scheduled Downtime pages, showing this host.

Post the entire /usr/local/nagiosxi/var/recurringdowntime.log on the forum.

Also, run:

Code: Select all

cat /usr/local/nagios/etc/recurringdowntime.cfg
and show the output in code wraps.

Re: Scheduled downtime duration field

Posted: Mon Sep 03, 2018 6:53 am
by CBoekhuis
Hi lmiltchev,

my colleague is out of the office, so I'm taking the post from here.

I created the recurring downtime as requested and ran the php script. Here are the 2 screenshots.
recuring_down.PNG
scheduled_down.PNG
The recurringdowntime.log hasn't been updated when the above steps were taken:

Code: Select all

nagios1:root:/usr/local/nagiosxi/var> ll /usr/local/nagiosxi/var/recurringdowntime.log                                     
-rw-r--r-- 1 nagios nagios 1288658 Sep  3 13:01 /usr/local/nagiosxi/var/recurringdowntime.log
The output of recurringdowntime.cfg is:

Code: Select all

define schedule {
        sid                     f4444af31c8db6f3827462b55f2cfd4a
        user                    XXXXXX
        comment                 test
        time                    13:50
        duration                660
        days_of_week
        days_of_month
        months_of_year
        schedule_type           host
        host_name               rhti2.boekhuis.nl
}
Note: in the above output I changed the username and also removed the existing schedules from other departments.

Greetings Hans

Re: Scheduled downtime duration field

Posted: Tue Sep 04, 2018 10:15 am
by lmiltchev
We haven't been able to recreate the issue in-house in Nagios XI 5.5.3. We will need to do some more digging into this. Please post the entire /usr/local/nagiosxi/var/recurringdowntime.log on the forum.

Also, run the following command and post the output:

Code: Select all

cat /usr/local/nagiosxi/var/xiversion
Is opening a ticket in our ticketing system an option for you? If it is, open a new ticket by going to:

https://support.nagios.com/tickets/

This will speed up the troubleshooting process and the resolution of the issue.

Re: Scheduled downtime duration field

Posted: Thu Sep 06, 2018 4:13 am
by CBoekhuis
Since you couldn't reproduce the error, I've retried the above test on another nagios server. Both servers are at the same release and are updated/patched at the same time. Since it's our DR and only monitors 1 hosts It will give us clean compact logging and output.

I create a recurring schedule for the host nagios1 and run the php /usr/local/nagiosxi/cron/recurring_downtime.php script:

Code: Select all

define schedule {
        sid                     adde1bb994f0c4c6ece1dc398fcc7ec8
        user                    bloha
        comment                 test
        time                    11:10
        duration                660
        days_of_week
        days_of_month
        months_of_year
        schedule_type           host
        host_name               nagios1.boekhuis.nl
}
screenshot recurring downtime:
recuring_down.PNG
Screenshot scheduled downtime:
scheduled_down.PNG
Then I ran the cronjob /usr/bin/php -q /usr/local/nagiosxi/cron/recurring_downtime.php >> /usr/local/nagiosxi/var/recurringdowntime.log 2>&1 to fill the recurringdowntime.log (runs only once an hour):
recurringdowntime.log
Output of cat /usr/local/nagios/etc/recurringdowntime.cfg:

Code: Select all

define schedule {
        sid                     adde1bb994f0c4c6ece1dc398fcc7ec8
        user                    bloha
        comment                 test
        time                    11:10
        duration                660
        days_of_week
        days_of_month
        months_of_year
        schedule_type           host
        host_name               nagios1.boekhuis.nl
}
So on this system it is reproducible. The first time this was noticed was late august while running 5.5.2, but I have no idea how long it might have been like this.

Re: Scheduled downtime duration field

Posted: Thu Sep 06, 2018 4:18 am
by CBoekhuis
Minor note, this behaviour is not necessarily related to recurring downtime. This also happens with an one off schedule.

Re: Scheduled downtime duration field

Posted: Thu Sep 06, 2018 9:45 am
by lmiltchev
This seems like a date/time/timezone issue... What is the timezone that you are using in the /etc/php.ini file? Is php and system time in sync? Go to Admin > System Config > System Profile > View System Info, and show us a screenshot of the "Date/Time" section.

Run the following commands and show the output:

Code: Select all

cat /usr/local/nagiosxi/var/xiversion
date
grep date.timezone /etc/php.ini | grep "^[^#;]"
echo 'select now();' | mysql -t -uroot -pnagiosxi
FYI - if you changed your default root mysql password from "nagiosxi" to something else, please modify the last command accordingly. Also, if your db is offloaded on a remote server, you will need to run your last command on the remote machine.

Note: If your system and php time is out of sync, you could fix the issue by following the steps, outlined in the document below:

https://assets.nagios.com/downloads/nag ... m_Time.pdf

It is very important that your mysql time is also correct. Changing your timezone in the php.ini *should* set mysql time too, and fix any sync issues.

Re: Scheduled downtime duration field

Posted: Thu Sep 06, 2018 10:04 am
by CBoekhuis
The output from the system profile:
date_time.PNG
cat /usr/local/nagiosxi/var/xiversion

Code: Select all

###################################
# DO NOT DELETE THIS FILE!
# Nagios XI version information
###################################
full=5.5.3
major=5
minor=5.3
releasedate=2018-08-28
release=5503
date

Code: Select all

Thu Sep  6 16:59:24 CEST 2018
grep date.timezone /etc/php.ini | grep "^[^#;]"

Code: Select all

date.timezone = Europe/Amsterdam
echo 'select now();' | mysql -t -uroot -pnagiosxi

Code: Select all

+---------------------+
| now()               |
+---------------------+
| 2018-09-06 16:59:25 |
+---------------------+
That seems to be good. Out of curiosity, how is the duration field calculated and in what php (?) script is it located? Or is it done in the database?

Re: Scheduled downtime duration field

Posted: Thu Sep 06, 2018 10:39 am
by lmiltchev
The calculation is done in the recurring_downtime.php script, which is not protected. You can open it in a text editor and review it. I believe the section you want to see is on the bottom:

Code: Select all

function get_downtimes()
{
    $downtimes = array();

    $dts = get_scheduled_downtime();
    if (!empty($dts)) {
        foreach ($dts as $d) {

            $start_time = convert_datetime_to_timestamp($d['scheduled_start_time']);
            $end_time = convert_datetime_to_timestamp($d['scheduled_end_time']);

            $duration = ($end_time - $start_time) / 1000;

            $downtime = array(
                'downtime_id'   => $d['internal_downtime_id'],
                'type'          => $d['downtime_type'],
                'host_name'     => $d['host_name'],
                'entry_time'    => convert_datetime_to_timestamp($d['entry_time']),
                'start_time'    => intval($start_time / 1000),
                'end_time'      => intval($end_time/ 1000),
                'author'        => $d['author_name'],
                'comment'       => $d['comment_data'],
                'fixed'         => $d['is_fixed'],
                'duration'      => intval($duration),
                'triggered_by'  => $d['triggered_by_id'],
                'is_in_effect'  => $d['was_started'],
                );

            if (!empty($d['service_description'])) {
                $downtime['service_description'] = $d['service_description'];
            }

            $downtimes[] = $downtime;
        }
    }

    return $downtimes;
Having said that, it's possible that the size of the scheduleddowntime_id table is too small, that's why the duration is "trimmed" to 9h 6m 7s... Can you run the following command and show the output?

Code: Select all

 echo 'describe nagios_scheduleddowntime;' | mysql -t -uroot -pnagiosxi nagios

Re: Scheduled downtime duration field

Posted: Fri Sep 07, 2018 2:14 am
by CBoekhuis
Hi,

Code: Select all

+------------------------+--------------+------+-----+---------------------+----------------+
| Field                  | Type         | Null | Key | Default             | Extra          |
+------------------------+--------------+------+-----+---------------------+----------------+
| scheduleddowntime_id   | int(11)      | NO   | PRI | NULL                | auto_increment |
| instance_id            | smallint(6)  | NO   | MUL | 0                   |                |
| downtime_type          | smallint(6)  | NO   |     | 0                   |                |
| object_id              | int(11)      | NO   |     | 0                   |                |
| entry_time             | datetime     | NO   |     | 0000-00-00 00:00:00 |                |
| author_name            | varchar(64)  | NO   |     |                     |                |
| comment_data           | varchar(255) | NO   |     |                     |                |
| internal_downtime_id   | int(11)      | NO   |     | 0                   |                |
| triggered_by_id        | int(11)      | NO   |     | 0                   |                |
| is_fixed               | smallint(6)  | NO   |     | 0                   |                |
| duration               | smallint(6)  | NO   |     | 0                   |                |
| scheduled_start_time   | datetime     | NO   |     | 0000-00-00 00:00:00 |                |
| scheduled_end_time     | datetime     | NO   |     | 0000-00-00 00:00:00 |                |
| was_started            | smallint(6)  | NO   |     | 0                   |                |
| actual_start_time      | datetime     | NO   |     | 0000-00-00 00:00:00 |                |
| actual_start_time_usec | int(11)      | NO   |     | 0                   |                |
+------------------------+--------------+------+-----+---------------------+----------------+