Local Server & GMT time in Notification %datetime%

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
zaji_nms
Posts: 616
Joined: Tue Oct 16, 2012 12:28 am

Local Server & GMT time in Notification %datetime%

Post by zaji_nms »

Dear Nagios Team

Our Notification is working great, currently the timestamp Date/Time: %datetime% is our Local Server but same time some customer need notification time in GMT, how can be achieve? Need both time as below. What have to do to less 3hours (GMTdatetime=LocalDatetime-3hours) in our Local Server Time (just for notification purpose), we do not want to change any server date/time.

Local Time: %datetime%
GMT Time: %GMTdatetime%

Regards
Last edited by zaji_nms on Sun Feb 21, 2016 3:43 am, edited 2 times in total.
Zajil NMS
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Local Server & GMT time in Notification %datetime%

Post by rkennedy »

At this time, it's only possible to have your system use one time.

I can file a feature request for this, if I understand correctly - you just want to change the time that is shown on an email notification that goes out?
Former Nagios Employee
zaji_nms
Posts: 616
Joined: Tue Oct 16, 2012 12:28 am

Re: Local Server & GMT time in Notification %datetime%

Post by zaji_nms »

Dear rKennedy

We want two dates, so its additional request, whatever current datetime, please keep it.

FYI, we have local domestic national customers for them current %datetime% is very okay but same time we have international customers, our international customers required link up/down time in GMT time, so its additional feature. I will call this macro as %GMTdatetime%. This moment only and only we required in Email Notifications. Its very minor feature add.

Host:
Service:
State:
Notification Type:
Info:
Local Time : %datetime%
GMT Time : %GMTdatetime%

Appreciate to file a feature request and any guideline/hint if can play around in our current version : Nagios XI 5.2.3 to achieve this quickly.

Regards
Zajil NMS
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: Local Server & GMT time in Notification %datetime%

Post by ssax »

*** Note: This will get reverted if you upgrade and will need to be reimplemented.
*** Make sure that you have known-good backups/vm snapshots before making any modifications

*** This will also only use the XI server's timezone to generate the GMT time.

You could edit this file:

Code: Select all

/usr/local/nagiosxi/html/includes/components/xicore/xicore.inc.php
Add this code:

Code: Select all

        $message = preg_replace('/%GMTdatetime%/', gmdate('Y-m-d H:i:s'), $message);
Below this code (It's in two places, one for email and one for mobile, around lines 283 and 411):

Code: Select all

        $message = process_notification_text($message, $meta);
Now you can use it in your template:

Code: Select all

%GMTdatetime%
Let me know if that works for you.
zaji_nms
Posts: 616
Joined: Tue Oct 16, 2012 12:28 am

Re: Local Server & GMT time in Notification %datetime%

Post by zaji_nms »

Dear ssax

Great....thanks its working fine. To be safe side keeping in my mind to avoid any conflict with Global & System variables, we added as below and if you implementing the same way (new feature request), we do not have to do any changes when we will upgrade our NagiosXI.

$message = preg_replace('/%ykGMTdatetime%/', gmdate('Y-m-d H:i:s'), $message);
Zajil NMS
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: Local Server & GMT time in Notification %datetime%

Post by ssax »

I'm glad that's working for you, good idea for changing the name. Are we okay to lock this thread and mark it as resolved?
zaji_nms
Posts: 616
Joined: Tue Oct 16, 2012 12:28 am

Re: Local Server & GMT time in Notification %datetime%

Post by zaji_nms »

Dear ssax

Yes you can but one favor as mentioned earlier if possible...........

we added as below and if you implementing the same way (new feature request), we do not have to do any changes when we will upgrade our NagiosXI.
$message = preg_replace('/%ykGMTdatetime%/', gmdate('Y-m-d H:i:s'), $message);
Zajil NMS
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Local Server & GMT time in Notification %datetime%

Post by lmiltchev »

Let's clarify - you want us to file a new feature request for adding the following line:

Code: Select all

$message = preg_replace('/%ykGMTdatetime%/', gmdate('Y-m-d H:i:s'), $message);
to "/usr/local/nagiosxi/html/includes/components/xicore/xicore.inc.php", correct?
Be sure to check out our Knowledgebase for helpful articles and solutions!
zaji_nms
Posts: 616
Joined: Tue Oct 16, 2012 12:28 am

Re: Local Server & GMT time in Notification %datetime%

Post by zaji_nms »

Yes , lmiltchev

Need to add twice, first time for Service other time for Host.

more /usr/local/nagiosxi/html/includes/components/xicore/xicore.inc.php | grep -n ykGMT

265 if ($notify == 1) {
266 if ($debug == true)
267 echo _("An email notification will be sent") . "...\n\n";
268
269 // get the user's email address
270 $email = get_user_attr($user_id, "email");
271
272 // get the email subject and message
273 if ($nt == "service") {
274 $subject = get_user_service_email_notification_subject($user_id);
275 $message = get_user_service_email_notification_message($user_id);
276 //get the GMT time in email notification
277 $message = preg_replace('/%ykGMTdatetime%/', gmdate('Y-m-d H:i:s'), $message);

278 } else {
279 $subject = get_user_host_email_notification_subject($user_id);
280 $message = get_user_host_email_notification_message($user_id);
281 //get the GMT time in email notification
282 $message = preg_replace('/%ykGMTdatetime%/', gmdate('Y-m-d H:i:s'), $message);

283 }

Regards
Zajil NMS
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Local Server & GMT time in Notification %datetime%

Post by lmiltchev »

I filed an internal feature request for adding this functionality (TASK ID 7885). FYI, there is no guarantee when/if this is going to be implemented. Thank you!

Is it safe to lock this thread?
Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked