Monthly Archives: July 2015

Nagios – Improve User Experience with Tampermonkey/Greasemonkey

Hello everyone, in these last few posts: Nagios – Change date format and Nagios – Use UTC I showed you how you can alter the date format and timezone of your Nagios server. Today I want to show you how you can improve User Experience with a simple Greasemonkey/Tampermonkey script by converting all date time values into relative time values (as seen on Facebook or used by SharePoint).

Important: If you want to use the below script without altering the “regexString” value you will need to follow this post of mine to make Nagios use the ISO8601 date format. And you need to follow this post to make Nagios use UTC.

Ok. Let´s get down to business 🙂

If you use Firefox install the Greasemonkey plugin or if you use Google Chrome install the Tampermonkey plugin to run the below script (If you use Internet Explorer you are unfortunately out of luck because neither Greasemonkey nor Tampermonkey are available for it to my knowledge). And here is the script:


// ==UserScript==
// @name Nagios - Date time to relative time
// @namespace https://theezitguy.wordpress.com/
// @version 1.0
// @description This script will turn every date time value into a relative time value (e.g. it will turn "2014-07-21 00:00:00" into "a year ago").
// @author theezitguy
// @match http://10.0.0.3/nagios/*
// @grant none
// @require http://momentjs.com/downloads/moment.js
// ==/UserScript==

//Get all textNodes of the website
textNodes = document.evaluate("//text()", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);

//Regex String - Search for date time values in ISO8601 format
var regexString = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/;
var searchRE = new RegExp(regexString);

//Go through all textNodes and replace date time values with relative time values
for (var i=0;i<textNodes.snapshotLength;i++)
{
var node = textNodes.snapshotItem(i);
node.data = node.data.replace(searchRE, moment.utc(node.data).fromNow());
}

The script will do the following:

It will go through every text node on the website and replace all date time values with relative time values.

Important: You need to alter the “@match” value to point to your Nagios server website before you can use it.

Here is a screenshot before I applied my script:

nagios_without_script_utc_time

And here is a screenshot after I applied my script:

nagios_with_script_relative_time

Well, that´s it. You can now easier read your data on your Nagios web interface.

Not bad, right? I hope you liked my today´s post and I hope to see you again next time 🙂

Sources:

http://momentjs.com/

http://forum.imerx.net/viewtopic.php?f=17&t=262&start=15

http://tuxradar.com/content/greasemonkey-beginners

http://www.digitoffee.com/programming/get-local-time-utc-using-moment-js/94/

Advertisements
Tagged

Nagios – Use UTC

Hello everyone, today I want to show you how you can configure your Nagios server to use UTC time format. This is useful to prevent confusion if you have people from multiple time zones looking at your web interface and it makes reports from your web interface much more useful since you do not need to convert times to UTC first. Ok, let´s do this 🙂 (I did this on Ubuntu 14.04.2 – Btw the server was configured to use CEST as default time zone)

First we will open the nagios.cfg file by running the following command:

sudo nano /usr/local/nagios/etc/nagios.cfg

Now search for “use_timezone” and add the following line of code:

use_timezone=UTC

To configure the Nagios web interface to use UTC too we will need to do the following to:

First open the nagios.conf file by running the following command:

sudo nano /etc/apache2/sites-available/nagios.conf

And add this line of code to the “/usr/local/nagios/sbin” section:

SetEnv TZ "UTC"

Your nagios.conf file should now look like this:


# SAMPLE CONFIG SNIPPETS FOR APACHE WEB SERVER
#
# This file contains examples of entries that need
# to be incorporated into your Apache web server
# configuration file. Customize the paths, etc. as
# needed to fit your system.

ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"

<Directory "/usr/local/nagios/sbin">
# SSLRequireSSL
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
# Order deny,allow
# Deny from all
# Allow from 127.0.0.1
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
SetEnv TZ "UTC"
</Directory>

Alias /nagios "/usr/local/nagios/share"

<Directory "/usr/local/nagios/share">
# SSLRequireSSL
Options None
AllowOverride None
Order allow,deny
Allow from all
# Order deny,allow
# Deny from all
# Allow from 127.0.0.1
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
</Directory>

Now you need to restart the Nagios and Apache services to apply the changes.

Run the following command to restart Nagios:

sudo service nagios restart

And run this command to restart Apache:

sudo service apache2 restart

And that´s it.

Here is a screenshot before we applied our changes:

nagios_web_interface_before_utc

And here is a screenshot after we applied our changes:

nagios_web_interface_utc

Well, that´s it. Now your Nagios server will use UTC.

I hope you liked my today´s post and I hope to see you again next time 🙂

Sources:

http://scratching.psybermonkey.net/2011/04/nagios-time-within-nagios-is-incorrect.html

https://ihazem.wordpress.com/2012/03/14/changing-timezone-on-nagios-core-web-interface/

Tagged ,

Nagios – Change date format

Hello everyone, today a customer asked me to change the default date format for the Nagios web interface since he wanted an international date format instead of the default us date format. I thought I should share the procedure so here is how to do it (I did this on Ubuntu 14.04.2):

This is how the web interface looked before:

nagios_date_format_default

Ok. First open the nagios.cfg file by running the following command:

sudo nano /usr/local/nagios/etc/nagios.cfg

nagios_change_date_format

Next search for “date_format” and change it from:

date_format=us

to:

date_format=iso8601

Save and then restart the Nagios service by running:

sudo service nagios restart

After the Nagios service has successfully restarted your web interface will look like this:

nagios_date_format_iso8601

Well, that´s it. Now all dates will be displayed in the international ISO8601 date format on your Nagios web interface. (Btw this does not change the log file format.)

I hope you liked my today´s post and I hope to see you again next time 🙂

Sources:

http://forums.meulie.net/t/nagios-log-format/2978

Tagged ,