Archive

Archive for the ‘Monitoring’ Category

Nagios: HOWTO convert timestamp values to a human-readable value / logfile

Problem description:

Nagios reports all messages to /usr/local/nagios/var/log/nagios.log. Unfortunately timestamps are stored in a none-human-readable way. If you are analyzing the logfile via tail, less, more, vi, etc. you are not able to determine the actual time of an event.

Problem resolution:

You can convert the timestamp values to a humand-readable string using the following simple perl command:

cat /usr/local/nagios/var/nagios.log | perl -pe 's/(\d+)/localtime($1)/e'

Example:

[root@linux01 ~]# tail -7lf /usr/local/nagios/var/nagios.log | perl -pe 's/(\d+)/localtime($1)/e'
[Wed May 15 12:00:12 2011] Caught SIGHUP, restarting...
[Wed May 15 12:00:12 2011] Nagios 3.2.3 starting... (PID=1234)
[Wed May 15 12:00:12 2011] Local time is Wed May 15 12:00:12 CEST 2011
[Wed May 15 12:00:12 2011] LOG VERSION: 2.0
[Wed May 15 12:14:02 2011] SERVICE ALERT: linux02.mydomain.intern;Status bond0;OK;HARD;4;OK - Bonding Mode: IEEE802.3adDynamic. eth0 up eth1 up
[Wed May 15 12:14:02 2011] SERVICE NOTIFICATION: nagiosadmin;linux02.mydomain.intern;Status bond0;OK;notify-service-by-email;OK - Bonding Mode: IEEE802.3adDynamic. eth0 up eth1 up
[Wed May 15 13:00:12 2011] Auto-save of retention data completed successfully.
Categories: Nagios Tags:

Linux/Nagios: sudo: sorry, you must have a tty to run sudo

Problem description:

If you are using Nagios or other monitoring products to check your servers, you might come into the situation running commands which require special permissions (e.g. like running them as the root-user). You have configured sudo permissions and your check runs fine on the terminal, but if the monitoring process/service tries to execute it, you are receiving the following message:

sudo: sorry, you must have a tty to run sudo

Cause:

By default sudo only allows to be executed with a tty:

[root@linux01 ~]# cat /etc/sudoers | grep requiretty
Defaults    requiretty
[root@linux01 ~]#

Problem resolution:

You can either disable requiretty or just disable it for the user you require to use sudo without tty (PREFERRED):

[root@linux01 ~]# cat /etc/sudoers | grep requiretty
Defaults    requiretty
Defaults:myosuser !requiretty
[root@linux01 ~]#
Categories: CentOS, Monitoring, Nagios, Oracle Linux, Red Hat Tags: