Page 1 of 1

Help me write Nagios Plugin???

Posted: Sat May 19, 2012 11:46 am
by mytrang
Currently, I'm writing a dissertation for Nagios plugin to monitor detect denial
of service attack by DOS. Who have tee tutorial help me, thanks very much.

Re: Help me write Nagios Plugin???

Posted: Tue May 22, 2012 3:38 pm
by lmiltchev
You can probably start by reviewing this:

http://nagiosplug.sourceforge.net/devel ... lines.html

Re: Help me write Nagios Plugin???

Posted: Wed May 23, 2012 12:56 pm
by mytrang
This link says too general. You can specify the steps to help my own? Thank you very much.

Re: Help me write Nagios Plugin???

Posted: Wed May 23, 2012 1:44 pm
by agriffin
A Nagios plugin is just a normal unix executable which exits with a particular exit code and outputs text to stdout in a particular format. The guidelines linked earlier cover the specifics. There is no step-by-step guide because it is expected that you know how to program already. You could try reading the source of a plugin or two if you're still confused; they're usually very short and simple.

Re: Help me write Nagios Plugin???

Posted: Wed May 23, 2012 11:37 pm
by mytrang
I will learn the techniques, Thanks very much for your reply ^^.

Re: Help me write Nagios Plugin???

Posted: Fri May 25, 2012 9:37 am
by agriffin
You're welcome. Good luck!

Re: Help me write Nagios Plugin???

Posted: Mon Jul 09, 2012 9:06 am
by mytrang
I have the code write about attack detect DoS with Nagios. Please you can see and explain mechanism of action for me?
my $program_name = "check_ddos.pl";
my $program_version = "0.4";
my $program_date = "02/2011";

# Libraries
#----------

use strict;
use lib "/usr/local/nagios/libexec";
use Getopt::Std;

# Globals variables
#------------------

my $netstat = '/bin/netstat -ant';
my %ERRORS = ('UNKNOWN' , '3',
'OK' , '0',
'WARNING', '1',
'CRITICAL', '2' );
my $state = "UNKNOWN";
my $answer = "";
my $warning;
my $critical;

# Programs argument management
#-----------------------------

my %opts = ();
getopts("hvw:c:", \%opts);
if ($opts{v}) {
# Display the version
print "$program_name $program_version ($program_date)\n";
exit(-1);
}
if ($opts{h} || (!$opts{w} || !$opts{c})) {
# Help
print "$program_name $program_version\n";
print "usage: ", $program_name," [options]\n";
print " -h: Print the command line help\n";
print " -v: Print the program version\n";
print " -w <int>: Warning value (number of SYN_RECV)\n";
print " -c <int>: Critical value (number of SYN_RECV)\n";
exit (-1);
}

# Get the warning value
if ($opts{w}) {
$warning = $opts{w};
}

# Get the warning value
if ($opts{c}) {
$critical = $opts{c};
}

# Main program
#-------------

system("$netstat > /tmp/check_ddos.res") == 0
or die "$state: $netstat failed ($?)";

my $ddos = `grep SYN_RECV /tmp/check_ddos.res | wc -l`;
chomp $ddos;
# my $output = `grep SYN_RECV /tmp/check_ddos.res | awk {'print \$5'} | cut -f 1 -d ":" | sort | uniq -c | sort -rn | head -10`;
my $output = `grep SYN_RECV /tmp/check_ddos.res | awk {'print \$5'} | cut -f 1 -d ":" | sort | uniq -c | sort -k1,1rn | head -10`;

if ($ddos >= $warning) {
if ($ddos >= $critical) {
$state = "CRITICAL";
} else {
$state = "WARNING";
}
print "DDOS attack.\nTop 10 SYN_RECV sources:\n$output";
} else {
$state = "OK";
print "No DDOS attack detected ($ddos/$warning).\n";
}

system("rm -f /tmp/check_ddos.res") == 0
or die "$state: Can not delete /tmp/check_ddos.res ($?)";

exit $ERRORS{$state};

# The end...

Re: Help me write Nagios Plugin???

Posted: Wed Jul 11, 2012 10:47 am
by agriffin
Sorry, but I'm not sure what you're asking. What do you mean by mechanism of action?