packages: nagios-plugin-check_redis/check_redis.pl (NEW)=?UTF-8?Q?=20?=- copy from https:...

glen glen at pld-linux.org
Tue Dec 20 11:50:26 CET 2011


Author: glen                         Date: Tue Dec 20 10:50:26 2011 GMT
Module: packages                      Tag: HEAD
---- Log message:
- copy from https://farmerluo.googlecode.com/files/check_redis.pl

---- Files affected:
packages/nagios-plugin-check_redis:
   check_redis.pl (NONE -> 1.1)  (NEW)

---- Diffs:

================================================================
Index: packages/nagios-plugin-check_redis/check_redis.pl
diff -u /dev/null packages/nagios-plugin-check_redis/check_redis.pl:1.1
--- /dev/null	Tue Dec 20 11:50:26 2011
+++ packages/nagios-plugin-check_redis/check_redis.pl	Tue Dec 20 11:50:21 2011
@@ -0,0 +1,146 @@
+#!/usr/bin/perl 
+
+# nagios: -epn
+
+################################################################################
+# check_redis - Nagios Plugin for Redis checks.
+#
+# @author  farmer.luo at gmail.com
+# @date    2010-05-12
+# @license GPL v2
+#
+# check_nagios.pl -h <redis host> -p <redis port> -w <warning time> -c <critica time>
+#
+# Run the script need:
+#
+# perl -MCPAN -e shell
+# install Redis
+#
+################################################################################
+
+use strict;
+use warnings;
+use Redis;
+use File::Basename;
+use utils qw($TIMEOUT %ERRORS &print_revision &support); 
+use Time::Local;
+use vars qw($opt_h); # Redis Ö÷»ú
+use vars qw($opt_p); # Redis ¶Ë¿Ú
+use vars qw($opt_w); # ³¬¹ýÕâ¸öʱ¼ä·¢³ö¾¯¸æ
+use vars qw($opt_c); # ³¬¹ýÕâ¸öʱ¼ä·¢³öÑÏÖØ¾¯¸æ
+use Getopt::Std;
+
+$opt_h = "";
+$opt_p = "6379";
+$opt_w = 5;
+$opt_c = 10;
+my $r = "";
+
+getopt('hpwcd');
+
+if ( $opt_h eq "" ) {
+	help();
+	exit(1);
+}
+
+my $start = time();
+
+redis_connect();
+
+# print $@;
+if ( $@ ) {
+	print "UNKNOWN - cann't connect to redis server:" . $opt_h . ".";
+	exit $ERRORS{"UNKNOWN"};
+}
+
+if ( redis_set() ) {
+	print "WARNING - redis server:" . $opt_h . ",set key error.";
+	exit $ERRORS{"WARNING"};
+}
+
+if ( redis_get() ) {
+	print "WARNING - redis server:" . $opt_h . ",get key error.";
+	exit $ERRORS{"WARNING"};
+}
+
+if ( redis_del() ) {
+	print "WARNING - redis server:" . $opt_h . ",del key error.";
+	exit $ERRORS{"WARNING"};
+}
+
+#sleep(3);
+my $stop = time();
+
+my $run = $stop - $start;
+
+if ( $run > $opt_c ) {
+	
+	print "CRITICAL - redis server(" . $opt_h . ") run for " . $run . " seconds!";
+	exit $ERRORS{"CRITICAL"};
+	
+} elsif ( $run > $opt_w ) {
+	
+	print "WARNING - redis server(" . $opt_h . ") run for " . $run . " seconds!";
+	exit $ERRORS{"WARNING"};
+	
+} else {
+	
+	redis_info();
+	redis_quit();
+	exit $ERRORS{"OK"};
+	
+}
+
+
+sub help{
+	
+	die "Usage:\n" , basename( $0 ) ,  " -h hostname -p port -w warning time -c critical time -d down time\n"
+	
+}
+
+sub redis_connect{
+	
+	my $redis_hp = $opt_h . ":" . $opt_p;
+	
+	eval{ $r = Redis->new( server => $redis_hp ); };
+	
+}
+
+sub redis_set{
+	
+	$r->set( redis_nagios_key => 'test' ) || return 1;
+	
+	return 0;
+}
+
+sub redis_get{
+	
+	my $value = $r->get( 'redis_nagios_key' ) || return 1;
+	
+	return 0;
+}
+
+sub redis_del{
+	
+	$r->del( 'redis_nagios_key' ) || return 1;
+	
+	return 0;
+}
+
+sub redis_info{
+	
+	my $info_hash = $r->info;
+	
+	print "OK - redis server(" . $opt_h . ") info:";
+	
+	while ( my ($key, $value) = each(%$info_hash) ) {
+	    print "$key => $value, ";
+	}
+
+}
+
+sub redis_quit{
+	
+	$r->quit();
+	
+}
\ No newline at end of file
================================================================



More information about the pld-cvs-commit mailing list