Month: December 2010

Nagios log file with normal date/time format

Nagios log file with normal date/time format

Introduction –

Nagios log file print the time in epoch time format. To convert that nagios log with normal time/date format you can use the following perl script.

Please download the script from here- http://www.indiangnu.org/wp-content/uploads/2010/nagios-log-pl.txt

* How to use it –

root@me:~# cat /etc/nagios/var/nagios.log | grep -i  NOTIFICATION | /root/nagmon/nagios-log.pl

* Pasting the code here…

root@me:~#  /root/nagmon/nagios-log.pl
#!/usr/bin/perl

# Author - IndianGNU.org
# Read nagios.log file and show log with
# converted date field in human-readable format
# 

$numArgs = $#ARGV + 1;

if ( $ARGV[0] eq "-h")
{
	print " * Usage: cat   like '/usr/local/nagios/var/nagios.log' | $0 \n"; exit 1;
}

sub epochtime
{
  my $epoch_time = shift;
  ($sec,$min,$hour,$day,$month,$year) = localtime($epoch_time);

  # correct the date and month for humans
  $year = 1900 + $year;
  $month++;

  return sprintf("%02d/%02d/%02d %02d:%02d:%02d", $year, $month, $day, $hour, $min, $sec);
}

while (<>)
{
  my $epoch = substr $_, 1, 10;
  my $remainder = substr $_, 13;
  my $human_date = &epochtime($epoch);
  printf("[%s] %s", $human_date, $remainder);
}
exit;

Thanks you,
Arun

Adding and Removing swap on Linux

Adding and Removing swap on Linux

Introduction –

Here we are going to create 4G swap file using cmd ‘dd’, later we will activate it.
we are named and create ‘/extraswap’ swap file for additional swap

dd command options
if = input file (read from FILE instead of stdin)
of = output file name (write to FILE instead of stdout)
bs = BYTES rate
count = BLOCKS (copy only number of block)

dd if=/dev/zero of=/extraswap bs=1024 count=4096000

***Adding extraswap Swap file

[root@ravi ~]# dd if=/dev/zero of=/extraswap bs=1024 count=4096000
4096000+0 records in
4096000+0 records out
4194304000 bytes (4.2 GB) copied, 162.277 seconds, 25.8 MB/s

Set up a Linux swap area using ‘mkswap’ command

[root@ravi ~]# mkswap /extraswap
Setting up swapspace version 1, size = 4194299 kB

Activate swap using ‘swapon’ command

[root@ravi ~]# swapon /extraswap

[root@ravi ~]# free -m
total       used       free     shared    buffers     cached
Mem:         16053       6148       9905          0        293       5488
-/+ buffers/cache:        367      15686
Swap:         3999          0       3999

Edit /etc/fstab and put below entry into it to swap on automatic after reboot server

/extraswap              none                    swap    defaults        0 0

*** Remove /extraswap file

[root@ravi ~]# swapoff /extraswap

Remove /extraswap swap file entry from /etc/fstab and run ‘mount -a

Delete /extraswap

[root@ravi ~]# rm /extraswap


-Ravi