commit 865f4ff4847288c1cf8fdefe698b1b7a544191d7
Author: Marc Dequènes (Duck) <Duck@DuckCorp.org>
Date:   Thu Apr 19 14:56:38 2012 +0200

    [evol] add corresponding scripts

diff --git a/scripts/stat_apache b/scripts/stat_apache
new file mode 100755
index 0000000..b72a94e
--- /dev/null
+++ b/scripts/stat_apache
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+PARAM=${1:-noexistent}
+
+BASE_URL=https://$(hostname --fqdn)
+
+CACHE_FILE=/tmp/zbx-apache
+test -z `/usr/bin/find ${CACHE_FILE} -mmin -5 2>/dev/null` && \
+	wget --bind-address 127.0.0.1 \
+		--user-agent=\"ApacheStats\/0.4 wget\/1.8\" -q \
+		-t3 -T5 --no-check-certificate \
+		-O ${CACHE_FILE} \
+		 ${BASE_URL}/server-status?auto
+
+cat ${CACHE_FILE} | perl -ne "print \$1 if m/^${PARAM}: (\d*\.?\d+)/"
+
diff --git a/scripts/stat_bind9 b/scripts/stat_bind9
new file mode 100755
index 0000000..5e18940
--- /dev/null
+++ b/scripts/stat_bind9
@@ -0,0 +1,35 @@
+#!/bin/sh
+
+PARAM=${1:-noexistent}
+
+case "${PARAM}" in
+  ipv4)
+	PATTERN="IPv4 requests received"
+	;;
+  ipv6)
+	PATTERN="IPv6 requests received"
+	;;
+  success)
+	PATTERN="queries resulted in successful answer"
+	;;
+  failure)
+	PATTERN=""
+	;;
+  nxdomain)
+	PATTERN="queries resulted in NXDOMAIN"
+	;;
+  nxrrset)
+	PATTERN="queries resulted in nxrrset"
+	;;
+  recursion)
+	PATTERN="queries caused recursion"
+	;;
+  referral)
+	PATTERN="queries resulted in non authoritative answer"
+	;;
+  *)
+    exit
+esac
+
+grep "${PATTERN}" /var/cache/bind/named.stats | head -n 1 | awk '{ print $1 }'
+
diff --git a/scripts/stat_mysql_slave_status b/scripts/stat_mysql_slave_status
new file mode 100755
index 0000000..cfc059f
--- /dev/null
+++ b/scripts/stat_mysql_slave_status
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+PARAM=${1:-noexistent}
+
+CACHE_FILE=/tmp/zbx-mysql_slave_status
+test -z `/usr/bin/find ${CACHE_FILE} -mmin -5 2>/dev/null` && \
+	echo "SHOW SLAVE STATUS\\G" | mysql --defaults-file=/etc/mysql/debian.cnf \
+	--batch --skip-pager --skip-column-names >${CACHE_FILE}
+cat ${CACHE_FILE} | perl -ne "print \$1 if m/\b${PARAM}: (.+)$/"
+
diff --git a/scripts/stat_mysql_status b/scripts/stat_mysql_status
new file mode 100755
index 0000000..68503ae
--- /dev/null
+++ b/scripts/stat_mysql_status
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+PARAM=${1:-noexistent}
+
+CACHE_FILE=/tmp/zbx-mysql_status
+test -z `/usr/bin/find ${CACHE_FILE} -mmin -5 2>/dev/null` && \
+	echo "SHOW GLOBAL STATUS" | mysql --defaults-file=/etc/mysql/debian.cnf \
+	--batch --skip-pager --skip-column-names >${CACHE_FILE}
+cat ${CACHE_FILE} | perl -ne "print \$1 if m/^${PARAM}\t([\d.]+)/"
+
diff --git a/scripts/stat_mysql_variables b/scripts/stat_mysql_variables
new file mode 100755
index 0000000..2c5e566
--- /dev/null
+++ b/scripts/stat_mysql_variables
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+PARAM=${1:-noexistent}
+
+CACHE_FILE=/tmp/zbx-mysql_variables
+test -z `/usr/bin/find ${CACHE_FILE} -mmin -5 2>/dev/null` && \
+	echo "SHOW VARIABLES" | mysql --defaults-file=/etc/mysql/debian.cnf \
+	--batch --skip-pager --skip-column-names >${CACHE_FILE}
+cat ${CACHE_FILE} | perl -ne "print \$1 if m/^${PARAM}\t([\d.]+)/"
+
diff --git a/scripts/stat_ntpd b/scripts/stat_ntpd
new file mode 100755
index 0000000..608f1ee
--- /dev/null
+++ b/scripts/stat_ntpd
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+# http://www.ntp.org/ntpfaq/NTP-s-sw-clocks-quality.htm
+
+PARAM=${1:-noexistent}
+
+ntpq -c rv | perl -ne "print \$1 if m/\b${PARAM}=([-]?\d+\.\d+)/"
+
diff --git a/scripts/stat_openldap b/scripts/stat_openldap
new file mode 100755
index 0000000..34fd856
--- /dev/null
+++ b/scripts/stat_openldap
@@ -0,0 +1,32 @@
+#!/usr/bin/perl
+
+# example parameter: /operations/add/monitorOpCompleted
+
+use warnings;
+use strict;
+use File::Basename;
+use IO::File;
+use Data::Dumper;
+
+my $param = $ARGV[0];
+unless ($param =~ m#^(/[a-zA-Z0-9 ]+)+$#)
+{
+	exit 1;
+}
+
+my $location = 'cn=' . join(',cn=', reverse(split(qr(/), dirname($param)))) . "monitor";
+my $attr = basename($param);
+
+my $fh = IO::File->new;
+# shell escapes are not possible, $param was check earlier using regex
+$fh->open('ldapsearch -Q -Y EXTERNAL -H ldapi:/// -b "' . $location . '" -s base -LLL "' . $attr . '" 2>/dev/null |');
+while (my $line = $fh->getline)
+{
+	if ($line =~ m/^$attr: (.*)$/)
+	{
+		print "$1\n";
+		exit 0;
+	}
+}
+
+exit 2;
diff --git a/scripts/stat_postfix_queue_size b/scripts/stat_postfix_queue_size
new file mode 100755
index 0000000..ca8f221
--- /dev/null
+++ b/scripts/stat_postfix_queue_size
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+QUEUE=$1
+
+qshape "${QUEUE}" | grep TOTAL | awk '{print $2}'
+
