Page 1 of 1
Local Server & GMT time in Notification %datetime%
Posted: Tue Feb 09, 2016 4:43 am
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
Re: Local Server & GMT time in Notification %datetime%
Posted: Tue Feb 09, 2016 11:54 am
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?
Re: Local Server & GMT time in Notification %datetime%
Posted: Wed Feb 10, 2016 12:24 am
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
Re: Local Server & GMT time in Notification %datetime%
Posted: Wed Feb 10, 2016 2:04 pm
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:
Let me know if that works for you.
Re: Local Server & GMT time in Notification %datetime%
Posted: Tue Feb 16, 2016 1:20 am
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);
Re: Local Server & GMT time in Notification %datetime%
Posted: Mon Feb 22, 2016 3:32 pm
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?
Re: Local Server & GMT time in Notification %datetime%
Posted: Wed Feb 24, 2016 12:49 am
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);
Re: Local Server & GMT time in Notification %datetime%
Posted: Wed Feb 24, 2016 1:59 pm
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?
Re: Local Server & GMT time in Notification %datetime%
Posted: Sun Feb 28, 2016 2:23 am
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
Re: Local Server & GMT time in Notification %datetime%
Posted: Mon Feb 29, 2016 10:24 am
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?