Title: [opsview-base] [10] copy linked files from opsview-core@9651
Revision
10
Author
aburzynski
Date
2012-07-30 13:32:22 +0100 (Mon, 30 Jul 2012)

Log Message

copy linked files from opsview-core@9651

Added Paths


Added: trunk/altinity-plugins/check_memory
===================================================================
--- trunk/altinity-plugins/check_memory	                        (rev 0)
+++ trunk/altinity-plugins/check_memory	2012-07-30 12:32:22 UTC (rev 10)
@@ -0,0 +1,186 @@
+#!/usr/bin/perl
+
+#  Copyright (C) 2003-2012 Opsview Limited. All rights reserved
+#
+#  This program is free software; you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License as published by
+#  the Free Software Foundation; either version 2 of the License, or
+#  (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software
+#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+use Getopt::Std;
+use IO::Socket;
+
+$script         = "check_memory";
+$script_version = "1.0 linux";
+
+$total_memory    = 0;
+$inactive_memory = 0;
+$free_memory     = 0;
+$buffer_memory   = 0;
+$cache_memory    = 0;
+$slab_memory     = 0;
+$used_swap       = 0;
+$free_swap       = 0;
+$total_swap      = 0;
+
+$warning  = 99;
+$critical = 100;
+
+# Do we have enough information?
+if ( !@ARGV ) {
+    print "Too few arguments\n";
+    usage();
+}
+
+getopts( "hw:c:" );
+if ($opt_h) {
+    usage();
+}
+if ($opt_w) {
+    $warning = $opt_w;
+}
+if ($opt_c) {
+    $critical = $opt_c;
+}
+
+if ( -e "/proc/meminfo" ) {
+    open INFILE, "</proc/meminfo" or die "Can't open /proc/meminfo $1";
+}
+
+my $counter = 0;
+foreach $line (<INFILE>) {
+    if ( $line =~ /MemTotal:/ ) {
+        $line =~ s/MemTotal://g;
+        $line =~ s/kB//g;
+        $line =~ s/ //g;
+        $line =~ s/\n//g;
+        $line         = $line / 1024;
+        $total_memory = $line;
+    }
+    elsif ( $line =~ /Inactive:/ ) {
+        $line =~ s/Inactive://g;
+        $line =~ s/kB//g;
+        $line =~ s/ //g;
+        $line =~ s/\n//g;
+        $line            = $line / 1024;
+        $inactive_memory = $line;
+    }
+    elsif ( $line =~ /MemFree:/ ) {
+        $line =~ s/MemFree://g;
+        $line =~ s/kB//g;
+        $line =~ s/ //g;
+        $line =~ s/\n//g;
+        $line        = $line / 1024;
+        $free_memory = $line;
+    }
+    elsif ( $line =~ /Buffers:/ ) {
+        $line =~ s/Buffers://g;
+        $line =~ s/kB//g;
+        $line =~ s/ //g;
+        $line =~ s/\n//g;
+        $line          = $line / 1024;
+        $buffer_memory = $line;
+    }
+    elsif ( $line =~ /SReclaimable:/ ) {
+        $line =~ s/SReclaimable://g;
+        $line =~ s/kB//g;
+        $line =~ s/ //g;
+        $line =~ s/\n//g;
+        $line        = $line / 1024;
+        $slab_memory = $line;
+    }
+    elsif ( $line =~ /Cached:/ ) {
+        if ( $line =~ /SwapCached:/ ) {
+        }
+        else {
+            $line =~ s/Cached://g;
+            $line =~ s/kB//g;
+            $line =~ s/ //g;
+            $line =~ s/\n//g;
+            $line         = $line / 1024;
+            $cache_memory = $line;
+        }
+    }
+    elsif ( $line =~ /SwapFree:/ ) {
+        $line =~ s/SwapFree://g;
+        $line =~ s/kB//g;
+        $line =~ s/ //g;
+        $line =~ s/\n//g;
+        $line      = $line / 1024;
+        $free_swap = $line;
+    }
+    elsif ( $line =~ /SwapTotal:/ ) {
+        $line =~ s/SwapTotal://g;
+        $line =~ s/kB//g;
+        $line =~ s/ //g;
+        $line =~ s/\n//g;
+        $line       = $line / 1024;
+        $total_swap = $line;
+    }
+}
+
+$real_used = (
+    $total_memory
+      - ( $cache_memory + $buffer_memory + $free_memory + $slab_memory )
+);
+$real_used_pc = (
+    100 - (
+          ( 100 / $total_memory )
+        * ( $cache_memory + $buffer_memory + $free_memory + $slab_memory )
+    )
+);
+
+# Some people have no swap.
+if ( $total_swap > 0 ) {
+    $swap_used = ( $total_swap - $free_swap );
+    $swap_used_pc = ( 100 - ( ( 100 / $total_swap ) * $free_swap ) );
+}
+else {
+    $swap_used    = 0;
+    $swap_used_pc = 0;
+}
+
+printf
+  "Usage: real %.0f%% (%.0f/%.0f MB), buffer: %.0f MB, cache: %.0f MB, swap: %.0f%% (%.0f/%.0f MB)|utilisation=%.0f\n",
+  $real_used_pc, $real_used, $total_memory, $buffer_memory, $cache_memory,
+  $swap_used_pc, $swap_used, $total_swap, $real_used_pc;
+
+if ( $swap_used_pc > $critical ) {
+    exit 2;
+}
+elsif ( $swap_used_pc > $warning ) {
+    exit 1;
+}
+if ( $real_used_pc > $critical ) {
+    exit 2;
+}
+elsif ( $real_used_pc > $warning ) {
+    exit 1;
+}
+exit 0;
+
+sub usage {
+    print << "USAGE";
+
+$script v$script_version
+
+Returns memory utilisation.
+
+Usage: $script -w <warning threshold> -c <critical threshold>
+Options: -w 		Warning threshold (integer)
+         -c 		Critical threshold (integer)
+
+		 }
+
+USAGE
+    exit 1;
+}


Property changes on: trunk/altinity-plugins/check_memory
___________________________________________________________________
Added: svn:executable
   + *

Added: trunk/altinity-plugins/check_memory_solaris
===================================================================
--- trunk/altinity-plugins/check_memory_solaris	                        (rev 0)
+++ trunk/altinity-plugins/check_memory_solaris	2012-07-30 12:32:22 UTC (rev 10)
@@ -0,0 +1,186 @@
+#!/usr/bin/perl
+#  Copyright (C) 2003-2012 Opsview Limited. All rights reserved
+#  W: http://www.opsview.com/
+#
+#  This program is free software; you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License as published by
+#  the Free Software Foundation; either version 2 of the License, or
+#  (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software
+#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+use strict;
+use warnings;
+
+use Getopt::Std;
+use IO::Socket;
+
+my $script         = "check_memory";
+my $script_version = " Solaris 1.4";
+
+my $swap_warning      = 9999;
+my $swap_critical     = 9999;
+my $memory_warning    = 9999;
+my $memory_critical   = 9999;
+my $scanrate_critical = 9999;
+my $warnonzero        = 0;
+my $direction         = "in";
+my $swapfiles         = 0;
+my $swap_blocks       = 0;
+my $swap_free         = 0;
+my $scanrate          = 0;
+my %options;
+my $memfree;
+my $memtotal_mb;
+my $memfree_mb;
+
+# Do we have enough information?
+if ( @ARGV < 2 ) {
+    print "Too few arguments\n";
+    usage();
+}
+
+getopts( "h:w:c:s:W:C:", \%options );
+if ( $options{h} ) {
+    usage();
+}
+
+$memory_warning    = $options{w} if ( defined $options{w} );
+$memory_critical   = $options{c} if ( defined $options{c} );
+$swap_warning      = $options{W} if ( defined $options{W} );
+$swap_critical     = $options{C} if ( defined $options{C} );
+$scanrate_critical = $options{s} if ( defined $options{s} );
+
+# note - run three times to a) avoid summary line, b) get more stable level
+my @vmstat = `/usr/bin/vmstat 1 3`;
+
+#my @vmstat = `vmstat`;
+
+#kthr      memory            page            disk          faults      cpu
+#r b w   swap  free  re  mf pi po fr de sr m1 m1 m1 m2   in   sy   cs us sy id
+#0 0 0 3587768 1621176 6 16  0  0  0  0  0  0  0  0  0  227  329  187  0  0 99
+
+{
+
+    #use last line only
+    my @line = split( / +/, $vmstat[-1] );
+    $memfree    = $line[5];
+    $scanrate   = $line[12];
+    $memfree_mb = int( $memfree / 1024 );
+}
+
+my @prtconf = `/usr/sbin/prtconf 2>/dev/null`;
+
+foreach my $line (@prtconf) {
+    if ( $line =~ /Memory size/ ) {
+        $line =~ s/Memory size://g;
+        $line =~ s/Megabytes//g;
+        $line =~ s/^\s+//;
+        $line =~ s/\s+$//;
+        $memtotal_mb = $line;
+    }
+}
+
+# print "total memory: $memtotal_mb\n";
+
+my $memutil_mb = ( $memtotal_mb - $memfree_mb );
+my $memutil_pc = ( ( 100 / $memtotal_mb ) * $memutil_mb );
+
+my @swap = `/usr/sbin/swap -l 2>/dev/null`;
+
+foreach my $line (@swap) {
+    if ( $line =~ /blocks/ ) {
+    }
+    else {
+        $line =~ s/^\s+//;
+        my @line = split( /\s+/, $line );
+        $swap_blocks = $swap_blocks + $line[3];
+        $swap_free   = $swap_free + $line[4];
+        $swapfiles++;
+    }
+}
+
+# swapfile             dev  swaplo blocks   free
+# /dev/swap            0,0       8 16787912 16594088
+# Block = 512 bytes
+
+my ( $swaptotal_mb, $swapfree_mb, $swaputil_mb, $swaputil_pc ) = ( 0, 0, 0, 0 );
+
+if ($swap_blocks) {
+    $swaptotal_mb = ( ( $swap_blocks * 512 ) / 1048576 );
+    $swapfree_mb  = ( ( $swap_free * 512 ) / 1048576 );
+    $swaputil_mb = $swaptotal_mb - $swapfree_mb;
+    $swaputil_pc = ( 100 - ( ( 100 / $swap_blocks ) * $swap_free ) );
+}
+
+if ( $scanrate >= $scanrate_critical ) {
+    printf
+      "CRITICAL! Memory: (%.0f MB, total: %.0f MB (%.0f%%)), Swap:(%.0f MB, total: %.0f MB (%.0f%%), files $swapfiles), Scanrate: %.0f|memory=%.0f%%;; swap=%.0f%%;; scanrate=%.0f;;\n",
+      $memutil_mb,  $memtotal_mb, $memutil_pc, $swaputil_mb, $swaptotal_mb,
+      $swaputil_pc, $scanrate,    $memutil_pc, $swaputil_pc, $scanrate;
+    exit 2;
+}
+elsif ( $memory_critical <= $memutil_pc ) {
+    printf
+      "CRITICAL! Memory: (%.0f MB, total: %.0f MB (%.0f%%)), Swap:(%.0f MB, total: %.0f MB (%.0f%%), files $swapfiles), Scanrate: %.0f|memory=%.0f%%;; swap=%.0f%%;; scanrate=%.0f;;\n",
+      $memutil_mb,  $memtotal_mb, $memutil_pc, $swaputil_mb, $swaptotal_mb,
+      $swaputil_pc, $scanrate,    $memutil_pc, $swaputil_pc, $scanrate;
+    exit 2;
+}
+elsif ( $swap_critical <= $swaputil_pc ) {
+    printf
+      "CRITICAL! Memory: (%.0f MB, total: %.0f MB (%.0f %%)), Swap:(%.0f MB, total: %.0f MB (%.0f %%), files $swapfiles), Scanrate: %.0f|memory=%.0f%%;; swap=%.0f%%;; scanrate=%.0f;;\n",
+      $memutil_mb,  $memtotal_mb, $memutil_pc, $swaputil_mb, $swaptotal_mb,
+      $swaputil_pc, $scanrate,    $memutil_pc, $swaputil_pc, $scanrate;
+    exit 2;
+}
+elsif ( $memory_warning <= $memutil_pc ) {
+    printf
+      "WARNING! Memory: (%.0f MB, total: %.0f MB (%.0f%%)), Swap:(%.0f MB, total: %.0f MB (%.0f%%), files $swapfiles), Scanrate: %.0f|memory=%.0f%%;; swap=%.0f%%;; scanrate=%.0f;;\n",
+      $memutil_mb,  $memtotal_mb, $memutil_pc, $swaputil_mb, $swaptotal_mb,
+      $swaputil_pc, $scanrate,    $memutil_pc, $swaputil_pc, $scanrate;
+
+    exit 1;
+}
+elsif ( $swap_warning <= $swaputil_pc ) {
+    printf
+      "WARNING! Memory: (%.0f MB, total: %.0f MB (%.0f %%)), Swap:(%.0f MB, total: %.0f MB (%.0f %%), files $swapfiles), Scanrate: %.0f|memory=%.0f%%;; swap=%.0f%%;; scanrate=%.0f;;\n",
+      $memutil_mb,  $memtotal_mb, $memutil_pc, $swaputil_mb, $swaptotal_mb,
+      $swaputil_pc, $scanrate,    $memutil_pc, $swaputil_pc, $scanrate;
+    exit 1;
+}
+else {
+    printf
+      "Memory: (%.0f MB, total: %.0f MB (%.0f%%)), Swap:(%.0f MB, total: %.0f MB (%.0f%%), files $swapfiles), Scanrate: %.0f|memory=%.0f%%;; swap=%.0f%%;; scanrate=%.0f;;\n",
+      $memutil_mb,  $memtotal_mb, $memutil_pc, $swaputil_mb, $swaptotal_mb,
+      $swaputil_pc, $scanrate,    $memutil_pc, $swaputil_pc, $scanrate;
+    exit 0;
+}
+
+exit 0;
+
+sub usage {
+    print << "USAGE";
+
+$script v$script_version
+
+Returns free memory in MB and scan rate as integer
+
+Usage: $script -w <warning threshold> -c <critical threshold> -s <scan rate>
+Options:    
+        -w         Warning RAM % threshold (integer)
+        -c         Critical RAM % threshold (integer)
+        -W         Warning SWAP % threshold (integer)
+        -C         Critical SWAP % threshold (integer)
+        -s         Scan rate (integer)
+
+USAGE
+    exit 1;
+}


Property changes on: trunk/altinity-plugins/check_memory_solaris
___________________________________________________________________
Added: svn:executable
   + *

Added: trunk/support_files/opsview-agent
===================================================================
--- trunk/support_files/opsview-agent	                        (rev 0)
+++ trunk/support_files/opsview-agent	2012-07-30 12:32:22 UTC (rev 10)
@@ -0,0 +1,151 @@
+#! /bin/sh 
+#
+#
+# AUTHORS:
+#	Copyright (C) 2003-2012 Opsview Limited. All rights reserved
+#
+#    This file is part of Opsview
+#
+#    Opsview is free software; you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation; either version 2 of the License, or
+#    (at your option) any later version.
+#
+#    Opsview is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with Opsview; if not, write to the Free Software
+#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+#
+
+### BEGIN INIT INFO
+# Provides:          opsview-agent
+# Required-Start:    $local_fs $remote_fs $syslog $named $network $time
+# Required-Stop:     $local_fs $remote_fs $syslog $named $network
+# Should-Start:
+# Should-Stop:
+# Default-Start:     2 3 4 5
+# Default-Stop:      0 1 6
+# Short-Description: Start/Stop the Nagios remote plugin execution daemon
+### END INIT INFO
+### CHKCONFIG INFO
+# chkconfig: 345 99 01
+# description: Control script for Opsview
+# processname: nrpe
+### END CHKCONFIG INFO
+
+# Switch to nagios if run as root
+id | grep "uid=0(" >/dev/null
+if [ $? = "0" ] ; then
+  case "$0" in
+		/*) cmd="$0" ;;
+		*) cmd=`which $0`
+		case "$cmd" in
+			/*) ;;
+			*) cmd="$PWD/$cmd";;
+		esac
+	;;
+	esac
+	exec su - nagios -c "$cmd $@"
+fi
+
+PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
+NAME=opsview-agent
+DESC=opsview-agent
+AGENT_BASE=/usr/local/nagios
+DAEMON=$AGENT_BASE/bin/nrpe
+CONFIG=$AGENT_BASE/etc/nrpe.cfg
+
+# get the correct PID file out of the config file
+PIDFILE=`grep "^pid_file=" $CONFIG | awk -F= '{print $2}'`
+if [ "x$PIDFILE" = "x" ]; then
+    echo "pid_file not set in $CONFIG - exiting"
+    exit 1
+fi
+
+die() { echo "$1"; exit 1; }
+
+getpid()
+{
+    if [ -f $PIDFILE ]; then
+        cat $PIDFILE
+    fi
+}
+
+status()
+{
+	PID=`getpid`
+	if [ "x$PID" != "x" ]; then
+        if kill -0 $PID 2>/dev/null; then
+            echo "NRPE is running as process $PID"
+            return 0
+        fi
+    fi
+
+    echo "NRPE is not running"
+    return 1
+}
+
+killproc_nrpe()
+{
+	PID=`getpid`
+	if [ "x$PID" != "x" ]; then
+        kill -0 $PID 2>/dev/null && kill $2 $PID
+    fi
+}
+
+test -x $DAEMON || exit 0
+
+case "$1" in
+	status)
+		status ; exit $?
+	;;
+
+  start)
+		if [ ! -f $CONFIG ]; then
+			echo "No nrpe.cfg - exiting"
+			exit 1
+		fi
+
+        # test to see if the pid file can be created
+        touch -a $PIDFILE 1>/dev/null 2>&1
+        if [ $? -ne 0 ]; then
+            echo "Cannot write to $PIDFILE - exiting"
+            exit 1
+        fi
+        # if touch created an remove empty file, remove it
+        test ! -s $PIDFILE && rm -f $PIDFILE
+
+		status nrpe > /dev/null && die "NRPE is already running"
+		
+		$DAEMON -c $CONFIG -d
+
+		echo "NRPE started"
+	;;
+
+  stop)
+		if status nrpe >/dev/null ; then
+			killproc_nrpe
+			status nrpe >/dev/null || echo "NRPE stopped"
+		else
+			echo "NRPE is not running"
+		fi
+
+	;;
+
+  restart)
+		$0 stop
+		sleep 1
+		$0 start
+	;;
+
+  *)
+		echo "Usage: $N {start|stop|restart|status}" 
+		exit 1
+	;;
+esac
+
+exit 0


Property changes on: trunk/support_files/opsview-agent
___________________________________________________________________
Added: svn:executable
   + *

_______________________________________________
Opsview-checkins mailing list
[email protected]
http://lists.opsview.org/lists/listinfo/opsview-checkins

Reply via email to