Missing scripts

This commit is contained in:
Kamil Porembinski 2016-05-02 09:29:00 +02:00
parent 7c43b446ea
commit 3c937983ef
12 changed files with 1643 additions and 1779 deletions

View File

@ -1,7 +1,6 @@
<?php
$item = $argv[1];
function file_get_contents_curl($url) {
$ch = curl_init();

16
bin/arduino.py Normal file
View File

@ -0,0 +1,16 @@
#!/usr/bin/env python
import serial
import sys
import time
ser=serial.Serial('/dev/ttyACM0', 9600, timeout=0.5)
ser.open()
try:
time.sleep(2)
ser.flush()
ser.write(sys.argv[1]+"\n")
response=ser.readline()
print response
# ser.close()
except:
print " ERROR "

68
bin/blacklist.sh Normal file
View File

@ -0,0 +1,68 @@
#!/bin/bash
# http://giantdorks.org/alain/shell-script-to-query-a-list-of-hostnames-or-ip-addresses-against-a-list-of-local-and-remote-dns-black-lists/
# Modified by Gerard Stanczak gerard@thecamels.org
# Usage: blacklist.sh DOMAIN
# IPs or hostnames to check if none provided as arguments to the script
hosts='
'
# Locally maintained list of DNSBLs to check
LocalList='
b.barracudacentral.org
'
# pipe delimited exclude list for remote lists
Exclude='spamtrap.drbl.drand.net|dnsbl.proxybl.org|^dnsbl.mailer.mobi$|^foo.bar$|^bar.baz$|^.*webiron.*$'
# Remotely maintained list of DNSBLs to check
WPurl="https://en.wikipedia.org/wiki/Comparison_of_DNS_blacklists"
WPlst=$(curl -s $WPurl | egrep "<td>([a-z]+\.){1,7}[a-z]+</td>" | sed -r "s|</?td>||g;/$Exclude/d")
# ---------------------------------------------------------------------
HostToIP()
{
if ( echo "$host" | egrep -q "[a-zA-Z]" ); then
IP=$(host "$host" | awk '/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/ {print$NF}')
else
IP="$host"
fi
}
Reverse()
{
echo $1 | awk -F. '{print$4"."$3"."$2"."$1}'
}
Check()
{
result=$(dig +short $rIP.$BL)
if [ -n "$result" ]; then
echo -e "$host LISTED $BL (answer = $result)"
else
echo -e "$host OK $BL"
fi
}
if [ -n "$1" ]; then
hosts=$@
fi
if [ -z "$hosts" ]; then
hosts=$(netstat -tn | awk '$4 ~ /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/ && $4 !~ /127.0.0/ {gsub(/:[0-9]+/,"",$4);} END{print$4}')
fi
for host in $hosts; do
HostToIP
rIP=$(Reverse $IP)
# Checking $IP against BLs from $WPurl"
for BL in $WPlst; do
Check
done
# Checking $IP against BLs from a local list"
for BL in $LocalList; do
Check
done
done

7
bin/check-update.sh Normal file
View File

@ -0,0 +1,7 @@
#!/bin/bash
day=$(date +%e)
if ((day <= 7)) ; then
result=`/usr/bin/yum -q check-update | grep -v "^$"`
echo -n "$result" > /tmp/yum-update-pending
chown zabbix.zabbix /tmp/yum-update-pending
fi

View File

@ -1,10 +1,4 @@
#!/bin/bash
# Script for HDD discovery
#
# Created by:
# Michał Macioszek, Taras Baran, Michal Gębora, Marcin Wilk, Maks Bednarek, Anna Fałek, Mikołaj Szczuraszek
disks=`ls -l /dev/sd* | awk '{print $NF}' | sed 's/[0-9]//g' | uniq`
echo -n "{\"data\":["

View File

@ -0,0 +1,19 @@
#!bin/bash
comma=1
echo -n "{\"data\":["
for i in $(sudo /bin/find /var/lib/mysql -type f -printf %p+%s= | tr "=" "\n" | grep -v "\/mysql\/mysql\/" | grep "\.ibd" | cut -d "+" -f 1 | sed 's/@002d/\-/g' | cut -d "/" -f 5- | sed 's/.ibd//g' ); do
dbname=$(echo $i | cut -d '/' -f 1)
tblname=$(echo $i | cut -d '/' -f 2)
if [ $comma -eq 0 ]; then
echo -n ","
fi
comma=0
echo -n "{\"{#DBNAME}\":\"$dbname\",\"{#TABLENAME}\":\"$tblname\"}"
done
echo -n "]}"

View File

@ -0,0 +1,29 @@
#!/bin/bash
cachefile='/tmp/mysqldbsize.log'
random=$RANDOM
if [ ! -e $cachefile ]; then
touch -d "2 hours ago" $cachefile
fi
if [ $# -ne 2 ]; then
echo "Usage: $0 dbname tablename"
exit 1
fi
cachefileage=$(($(date +%s) - $(stat -c %Y $cachefile)))
process_running=$(ps aux | grep 'find /var/lib/mysql' | grep -v "grep" | wc -l)
if [ "$cachefileage" -gt 60 ] && [ "$process_running" -eq 0 ]; then
sudo /bin/find /var/lib/mysql -type f -printf %p+%s= | tr "=" "\n" | grep -v "\/mysql\/mysql\/" | grep "\.ibd" | sed 's/@002d/\-/g' > $cachefile.$random
if [ $? -eq 0 ]; then
mv $cachefile.$random $cachefile
chown zabbix.zabbix $cachefile
fi
fi
grep "/$1/" $cachefile | grep "/$2\.ibd" | cut -d "+" -f 2

12
bin/pgsql_find_db.sh Normal file
View File

@ -0,0 +1,12 @@
#!/bin/bash
# If you want to monitor "foo" and "bar" databases, you set the GETDB as
# GETDB="select datname from pg_database where datname in ('foo','bar');"
# CREATE USER zabbix WITH PASSWORD 'asfrtgrg432f';
# GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO zabbix;
GETDB="select datname from pg_database where datistemplate = 'f';"
for dbname in $(psql -U zabbix -d postgres -t -c "${GETDB}"); do
dblist="$dblist,"'{"{#DBNAME}":"'$dbname'"}'
done
echo '{"data":['${dblist#,}' ]}'

View File

@ -1,24 +1,11 @@
<?php
# ============================================================================
# This is a script to retrieve information from a MySQL server for input to a
# Cacti graphing process. It is hosted at
# http://code.google.com/p/mysql-cacti-templates/.
#
# This program is copyright (c) 2007 Baron Schwartz. Feedback and improvements
# are welcome.
#
# THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
# MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
# 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, version 2.
#
# 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.
# This program is part of Percona Monitoring Plugins
# License: GPL License (see COPYING)
# Copyright 2008-2015 Baron Schwartz, 2012-2015 Percona
# Authors:
# Baron Schwartz, Roman Vynar
# ============================================================================
# ============================================================================
@ -41,19 +28,27 @@ if ( !array_key_exists('SCRIPT_FILENAME', $_SERVER)
# .cnf extension.
# ============================================================================
$mysql_user = 'zabbix';
$mysql_pass = 'ha7jqnlacwefrs';
$mysql_pass = 'wJ44mR6a59r3duDr';
$mysql_port = 3306;
$mysql_ssl = FALSE; # Whether to use SSL to connect to MySQL.
$mysql_ssl_key = '/etc/pki/tls/certs/mysql/client-key.pem';
$mysql_ssl_cert = '/etc/pki/tls/certs/mysql/client-cert.pem';
$mysql_ssl_ca = '/etc/pki/tls/certs/mysql/ca-cert.pem';
$heartbeat = FALSE; # Whether to use pt-heartbeat table for repl. delay calculation.
$heartbeat_utc = FALSE; # Whether pt-heartbeat is run with --utc option.
$heartbeat_server_id = 0; # Server id to associate with a heartbeat. Leave 0 if no preference.
$heartbeat_table = 'percona.heartbeat'; # db.tbl.
$heartbeat = ''; # db.tbl in case you use mk-heartbeat from Maatkit.
$cache_dir = '/tmp'; # If set, this uses caching to avoid multiple calls.
$poll_time = 300; # Adjust to match your polling interval.
$timezone = null; # If not set, uses the system default. Example: "UTC"
$chk_options = array (
'innodb' => true, # Do you want to check InnoDB statistics?
'master' => true, # Do you want to check binary logging?
'slave' => true, # Do you want to check slave status?
'procs' => true, # Do you want to check SHOW PROCESSLIST?
'get_qrt' => true, # Get query response times from Percona Server?
'get_qrt' => true, # Get query response times from Percona Server or MariaDB?
);
$use_ss = FALSE; # Whether to use the script server or not
@ -63,13 +58,18 @@ $debug_log = FALSE; # If $debug_log is a filename, it'll be used.
# ============================================================================
# You should not need to change anything below this line.
# ============================================================================
$version = "1.1.8";
$version = '1.1.5';
# ============================================================================
# Include settings from an external config file (issue 39).
# Include settings from an external config file.
# ============================================================================
if ( file_exists(__FILE__ . '.cnf' ) ) {
if ( file_exists('/etc/cacti/' . basename(__FILE__) . '.cnf' ) ) {
require('/etc/cacti/' . basename(__FILE__) . '.cnf');
debug('Found configuration file /etc/cacti/' . basename(__FILE__) . '.cnf');
}
elseif ( file_exists(__FILE__ . '.cnf' ) ) {
require(__FILE__ . '.cnf');
debug('Found configuration file ' . __FILE__ . '.cnf');
}
# Make this a happy little script even when there are errors.
@ -104,6 +104,18 @@ if ( $use_ss ) {
}
}
# ============================================================================
# Set the default timezone either to the configured, system timezone, or the
# default set above in the script.
# ============================================================================
if ( function_exists("date_default_timezone_set")
&& function_exists("date_default_timezone_get") ) {
$tz = ($timezone ? $timezone : @date_default_timezone_get());
if ( $tz ) {
@date_default_timezone_set($tz);
}
}
# ============================================================================
# Make sure we can also be called as a script.
# ============================================================================
@ -156,8 +168,12 @@ if ( !function_exists('array_change_key_case') ) {
# Validate that the command-line options are here and correct
# ============================================================================
function validate_options($options) {
debug($options);
$opts = array('host', 'items', 'user', 'pass', 'heartbeat', 'nocache', 'port');
$opts = array('host', 'items', 'user', 'pass', 'nocache', 'port', 'server-id');
# Show help
if ( array_key_exists('help', $options) ) {
usage('');
}
# Required command-line options
foreach ( array('host', 'items') as $option ) {
if ( !isset($options[$option]) || !$options[$option] ) {
@ -175,21 +191,20 @@ function validate_options($options) {
# Print out a brief usage summary
# ============================================================================
function usage($message) {
global $mysql_user, $mysql_pass, $mysql_port, $heartbeat;
global $mysql_user, $mysql_pass, $mysql_port;
$usage = <<<EOF
$message
Usage: php ss_get_mysql_stats.php --host <host> --items <item,...> [OPTION]
--host Hostname to connect to; use host:port syntax to specify a port
Use :/path/to/socket if you want to connect via a UNIX socket
--host MySQL host
--items Comma-separated list of the items whose data you want
--user MySQL username; defaults to $mysql_user if not given
--pass MySQL password; defaults to $mysql_pass if not given
--heartbeat MySQL heartbeat table; defaults to '$heartbeat' (see mk-heartbeat)
--user MySQL username
--pass MySQL password
--port MySQL port
--server-id Server id to associate with a heartbeat if heartbeat usage is enabled
--nocache Do not cache results in a file
--port MySQL port; defaults to $mysql_port if not given
--mysql_ssl Add the MYSQL_CLIENT_SSL flag to mysql_connect() call
--help Show usage
EOF;
die($usage);
@ -200,39 +215,23 @@ EOF;
# return them as an array ( arg => value )
# ============================================================================
function parse_cmdline( $args ) {
$result = array();
$cur_arg = '';
foreach ($args as $val) {
if ( strpos($val, '--') === 0 ) {
if ( strpos($val, '--no') === 0 ) {
# It's an option without an argument, but it's a --nosomething so
# it's OK.
$result[substr($val, 2)] = 1;
$cur_arg = '';
$options = array();
while (list($tmp, $p) = each($args)) {
if (strpos($p, '--') === 0) {
$param = substr($p, 2);
$value = null;
$nextparam = current($args);
if ($nextparam !== false && strpos($nextparam, '--') !==0) {
list($tmp, $value) = each($args);
}
elseif ( $cur_arg ) { # Maybe the last --arg was an option with no arg
if ( $cur_arg == '--user' || $cur_arg == '--pass' || $cur_arg == '--port' ) {
# Special case because Cacti will pass these without an arg
$cur_arg = '';
}
else {
die("No arg: $cur_arg\n");
}
}
else {
$cur_arg = $val;
}
}
else {
$result[substr($cur_arg, 2)] = $val;
$cur_arg = '';
$options[$param] = $value;
}
}
if ( $cur_arg && ($cur_arg != '--user' && $cur_arg != '--pass' && $cur_arg != '--port') ) {
die("No arg: $cur_arg\n");
if ( array_key_exists('host', $options) ) {
$options['host'] = substr($options['host'], 0, 4) == 'tcp:' ? substr($options['host'], 4) : $options['host'];
}
debug($result);
return $result;
debug($options);
return $options;
}
# ============================================================================
@ -240,43 +239,24 @@ function parse_cmdline( $args ) {
# top of this file.
# ============================================================================
function ss_get_mysql_stats( $options ) {
# Process connection options and connect to MySQL.
global $debug, $mysql_user, $mysql_pass, $heartbeat, $cache_dir, $poll_time,
$chk_options, $mysql_port, $mysql_ssl;
# Process connection options.
global $debug, $mysql_user, $mysql_pass, $cache_dir, $poll_time, $chk_options,
$mysql_port, $mysql_ssl, $mysql_ssl_key, $mysql_ssl_cert, $mysql_ssl_ca,
$heartbeat, $heartbeat_table, $heartbeat_server_id, $heartbeat_utc;
# Connect to MySQL.
$user = isset($options['user']) ? $options['user'] : $mysql_user;
$pass = isset($options['pass']) ? $options['pass'] : $mysql_pass;
$host = $options['host'];
$port = isset($options['port']) ? $options['port'] : $mysql_port;
$heartbeat = isset($options['heartbeat']) ? $options['heartbeat'] : $heartbeat;
# If there is a port, or if it's a non-standard port, we add ":$port" to the
# hostname.
$host_str = $options['host']
. (isset($options['port']) || $port != 3306 ? ":$port" : '');
debug(array('connecting to', $host_str, $user, $pass));
if ( !extension_loaded('mysql') ) {
debug("The MySQL extension is not loaded");
die("The MySQL extension is not loaded");
}
if ( $mysql_ssl || (isset($options['mysql_ssl']) && $options['mysql_ssl']) ) {
$conn = mysql_connect($host_str, $user, $pass, true, MYSQL_CLIENT_SSL);
}
else {
$conn = mysql_connect($host_str, $user, $pass);
}
if ( !$conn ) {
die("MySQL: " . mysql_error());
}
$heartbeat_server_id = isset($options['server-id']) ? $options['server-id'] : $heartbeat_server_id;
$sanitized_host
= str_replace(array(":", "/"), array("", "_"), $options['host']);
$cache_file = "$cache_dir/$sanitized_host-mysql_cacti_stats.txt"
. (isset($options['port']) || $port != 3306 ? ":$port" : '');
$sanitized_host = str_replace(array(":", "/"), array("", "_"), $host);
$cache_file = "$cache_dir/$sanitized_host-mysql_cacti_stats.txt" . ($port != 3306 ? ":$port" : '');
debug("Cache file is $cache_file");
# First, check the cache.
$fp = null;
if ( !isset($options['nocache']) ) {
if ( $cache_dir && !array_key_exists('nocache', $options) ) {
if ( $fp = fopen($cache_file, 'a+') ) {
$locked = flock($fp, 1); # LOCK_SH
if ( $locked ) {
@ -308,14 +288,36 @@ function ss_get_mysql_stats( $options ) {
}
}
else {
debug("Couldn't lock the cache file, ignoring it.");
$fp = null;
debug("Couldn't lock the cache file, ignoring it");
}
}
else {
$fp = null;
debug("Couldn't open the cache file");
}
}
else {
$fp = null;
debug("Couldn't open the cache file");
debug("Caching is disabled.");
}
# Connect to MySQL.
debug(array('Connecting to', $host, $port, $user, $pass));
if ( !extension_loaded('mysqli') ) {
debug("PHP MySQLi extension is not loaded");
die("PHP MySQLi extension is not loaded");
}
if ( $mysql_ssl ) {
$conn = mysqli_init();
mysqli_ssl_set($conn, $mysql_ssl_key, $mysql_ssl_cert, $mysql_ssl_ca, NULL, NULL);
mysqli_real_connect($conn, $host, $user, $pass, NULL, $port);
}
else {
$conn = mysqli_connect($host, $user, $pass, NULL, $port);
}
if ( mysqli_connect_errno() ) {
debug("MySQL connection failed: " . mysqli_connect_error());
die("ERROR: " . mysqli_connect_error());
}
# Set up variables.
@ -334,22 +336,22 @@ function ss_get_mysql_stats( $options ) {
'innodb_sem_wait_time_ms' => 0,
# Values for the 'state' column from SHOW PROCESSLIST (converted to
# lowercase, with spaces replaced by underscores)
'State_closing_tables' => null,
'State_copying_to_tmp_table' => null,
'State_end' => null,
'State_freeing_items' => null,
'State_init' => null,
'State_locked' => null,
'State_login' => null,
'State_preparing' => null,
'State_reading_from_net' => null,
'State_sending_data' => null,
'State_sorting_result' => null,
'State_statistics' => null,
'State_updating' => null,
'State_writing_to_net' => null,
'State_none' => null,
'State_other' => null, # Everything not listed above
'State_closing_tables' => 0,
'State_copying_to_tmp_table' => 0,
'State_end' => 0,
'State_freeing_items' => 0,
'State_init' => 0,
'State_locked' => 0,
'State_login' => 0,
'State_preparing' => 0,
'State_reading_from_net' => 0,
'State_sending_data' => 0,
'State_sorting_result' => 0,
'State_statistics' => 0,
'State_updating' => 0,
'State_writing_to_net' => 0,
'State_none' => 0,
'State_other' => 0, # Everything not listed above
);
# Get SHOW STATUS and convert the name-value array into a simple
@ -367,7 +369,14 @@ function ss_get_mysql_stats( $options ) {
# Get SHOW SLAVE STATUS, and add it to the $status array.
if ( $chk_options['slave'] ) {
$result = run_query("SHOW SLAVE STATUS", $conn);
# Leverage lock-free SHOW SLAVE STATUS if available
$result = run_query("SHOW SLAVE STATUS NONBLOCKING", $conn);
if ( !$result ) {
$result = run_query("SHOW SLAVE STATUS NOLOCK", $conn);
if ( !$result ) {
$result = run_query("SHOW SLAVE STATUS", $conn);
}
}
$slave_status_rows_gotten = 0;
foreach ( $result as $row ) {
$slave_status_rows_gotten++;
@ -379,9 +388,16 @@ function ss_get_mysql_stats( $options ) {
# Check replication heartbeat, if present.
if ( $heartbeat ) {
if ( $heartbeat_utc ) {
$now_func = 'UNIX_TIMESTAMP(UTC_TIMESTAMP)';
}
else {
$now_func = 'UNIX_TIMESTAMP()';
}
$result2 = run_query(
"SELECT GREATEST(0, UNIX_TIMESTAMP() - UNIX_TIMESTAMP(ts) - 1)"
. " AS delay FROM $heartbeat WHERE id = 1", $conn);
"SELECT MAX($now_func - ROUND(UNIX_TIMESTAMP(ts)))"
. " AS delay FROM $heartbeat_table"
. " WHERE $heartbeat_server_id = 0 OR server_id = $heartbeat_server_id", $conn);
$slave_delay_rows_gotten = 0;
foreach ( $result2 as $row2 ) {
$slave_delay_rows_gotten++;
@ -391,7 +407,7 @@ function ss_get_mysql_stats( $options ) {
$status['slave_lag'] = $row2['delay'];
}
else {
debug("Couldn't get slave lag from $heartbeat");
debug("Couldn't get slave lag from $heartbeat_table");
}
}
if ( $slave_delay_rows_gotten == 0 ) {
@ -443,6 +459,10 @@ function ss_get_mysql_stats( $options ) {
if ( $state == '' ) {
$state = 'none';
}
# MySQL 5.5 replaces the 'Locked' state with a variety of "Waiting for
# X lock" types of statuses. Wrap these all back into "Locked" because
# we don't really care about the type of locking it is.
$state = preg_replace('/^(Table lock|Waiting for .*lock)$/', 'Locked', $state);
$state = str_replace(' ', '_', strtolower($state));
if ( array_key_exists("State_$state", $status) ) {
increment($status, "State_$state", 1);
@ -453,35 +473,59 @@ function ss_get_mysql_stats( $options ) {
}
}
# Get SHOW ENGINES to be able to determine whether InnoDB is present.
$engines = array();
$result = run_query("SHOW ENGINES", $conn);
foreach ( $result as $row ) {
$engines[$row[0]] = $row[1];
}
# Get SHOW INNODB STATUS and extract the desired metrics from it, then add
# those to the array too.
if ( $chk_options['innodb']
&& array_key_exists('have_innodb', $status)
&& $status['have_innodb'] == 'YES'
&& array_key_exists('InnoDB', $engines)
&& $engines['InnoDB'] == 'YES'
|| $engines['InnoDB'] == 'DEFAULT'
) {
$result = run_query("SHOW /*!50000 ENGINE*/ INNODB STATUS", $conn);
$istatus_text = $result[0]['Status'];
$istatus_vals = get_innodb_array($istatus_text);
# Get response time histogram from Percona Server if enabled.
# Get response time histogram from Percona Server or MariaDB if enabled.
if ( $chk_options['get_qrt']
&& isset($status['have_response_time_distribution'])
&& ($status['have_response_time_distribution'] == 'YES'))
&& (( isset($status['have_response_time_distribution'])
&& $status['have_response_time_distribution'] == 'YES')
|| (isset($status['query_response_time_stats'])
&& $status['query_response_time_stats'] == 'ON')) )
{
debug('Getting query time histogram');
$i = 0;
$result = run_query(
"SELECT `count`, total * 1000000 AS total "
"SELECT `count`, ROUND(total * 1000000) AS total "
. "FROM INFORMATION_SCHEMA.QUERY_RESPONSE_TIME "
. "WHERE `time` <> 'TOO LONG'",
$conn);
foreach ( $result as $row ) {
if ( $i > 13 ) {
# It's possible that the number of rows returned isn't 14.
# Don't add extra status counters.
break;
}
$count_key = sprintf("Query_time_count_%02d", $i);
$total_key = sprintf("Query_time_total_%02d", $i);
$status[$count_key] = $row['count'];
$status[$total_key] = $row['total'];
$i++;
}
# It's also possible that the number of rows returned is too few.
# Don't leave any status counters unassigned; it will break graphs.
while ( $i <= 13 ) {
$count_key = sprintf("Query_time_count_%02d", $i);
$total_key = sprintf("Query_time_total_%02d", $i);
$status[$count_key] = 0;
$status[$total_key] = 0;
$i++;
}
}
else {
debug('Not getting time histogram because it is not enabled');
@ -506,6 +550,8 @@ function ss_get_mysql_stats( $options ) {
'Innodb_rows_inserted' => 'rows_inserted',
'Innodb_rows_read' => 'rows_read',
'Innodb_rows_updated' => 'rows_updated',
'Innodb_buffer_pool_reads' => 'pool_reads',
'Innodb_buffer_pool_read_requests' => 'pool_read_requests',
);
# If the SHOW STATUS value exists, override...
@ -548,204 +594,221 @@ function ss_get_mysql_stats( $options ) {
}
# Define the variables to output. I use shortened variable names so maybe
# it'll all fit in 1024 bytes for Cactid and Spine's benefit. This list must
# come right after the word MAGIC_VARS_DEFINITIONS. The Perl script parses
# it and uses it as a Perl variable.
# it'll all fit in 1024 bytes for Cactid and Spine's benefit. Strings must
# have some non-hex characters (non a-f0-9) to avoid a Cacti bug. This list
# must come right after the word MAGIC_VARS_DEFINITIONS. The Perl script
# parses it and uses it as a Perl variable.
$keys = array(
'Key_read_requests' => 'a0',
'Key_reads' => 'a1',
'Key_write_requests' => 'a2',
'Key_writes' => 'a3',
'history_list' => 'a4',
'innodb_transactions' => 'a5',
'read_views' => 'a6',
'current_transactions' => 'a7',
'locked_transactions' => 'a8',
'active_transactions' => 'a9',
'pool_size' => 'aa',
'free_pages' => 'ab',
'database_pages' => 'ac',
'modified_pages' => 'ad',
'pages_read' => 'ae',
'pages_created' => 'af',
'pages_written' => 'ag',
'file_fsyncs' => 'ah',
'file_reads' => 'ai',
'file_writes' => 'aj',
'log_writes' => 'ak',
'pending_aio_log_ios' => 'al',
'pending_aio_sync_ios' => 'am',
'pending_buf_pool_flushes' => 'an',
'pending_chkp_writes' => 'ao',
'pending_ibuf_aio_reads' => 'ap',
'pending_log_flushes' => 'aq',
'pending_log_writes' => 'ar',
'pending_normal_aio_reads' => 'as',
'pending_normal_aio_writes' => 'at',
'ibuf_inserts' => 'au',
'ibuf_merged' => 'av',
'ibuf_merges' => 'aw',
'spin_waits' => 'ax',
'spin_rounds' => 'ay',
'os_waits' => 'az',
'rows_inserted' => 'b0',
'rows_updated' => 'b1',
'rows_deleted' => 'b2',
'rows_read' => 'b3',
'Table_locks_waited' => 'b4',
'Table_locks_immediate' => 'b5',
'Slow_queries' => 'b6',
'Open_files' => 'b7',
'Open_tables' => 'b8',
'Opened_tables' => 'b9',
'innodb_open_files' => 'ba',
'open_files_limit' => 'bb',
'table_cache' => 'bc',
'Aborted_clients' => 'bd',
'Aborted_connects' => 'be',
'Max_used_connections' => 'bf',
'Slow_launch_threads' => 'bg',
'Threads_cached' => 'bh',
'Threads_connected' => 'bi',
'Threads_created' => 'bj',
'Threads_running' => 'bk',
'max_connections' => 'bl',
'thread_cache_size' => 'bm',
'Connections' => 'bn',
'slave_running' => 'bo',
'slave_stopped' => 'bp',
'Slave_retried_transactions' => 'bq',
'slave_lag' => 'br',
'Slave_open_temp_tables' => 'bs',
'Qcache_free_blocks' => 'bt',
'Qcache_free_memory' => 'bu',
'Qcache_hits' => 'bv',
'Qcache_inserts' => 'bw',
'Qcache_lowmem_prunes' => 'bx',
'Qcache_not_cached' => 'by',
'Qcache_queries_in_cache' => 'bz',
'Qcache_total_blocks' => 'c0',
'query_cache_size' => 'c1',
'Questions' => 'c2',
'Com_update' => 'c3',
'Com_insert' => 'c4',
'Com_select' => 'c5',
'Com_delete' => 'c6',
'Com_replace' => 'c7',
'Com_load' => 'c8',
'Com_update_multi' => 'c9',
'Com_insert_select' => 'ca',
'Com_delete_multi' => 'cb',
'Com_replace_select' => 'cc',
'Select_full_join' => 'cd',
'Select_full_range_join' => 'ce',
'Select_range' => 'cf',
'Select_range_check' => 'cg',
'Select_scan' => 'ch',
'Sort_merge_passes' => 'ci',
'Sort_range' => 'cj',
'Sort_rows' => 'ck',
'Sort_scan' => 'cl',
'Created_tmp_tables' => 'cm',
'Created_tmp_disk_tables' => 'cn',
'Created_tmp_files' => 'co',
'Bytes_sent' => 'cp',
'Bytes_received' => 'cq',
'innodb_log_buffer_size' => 'cr',
'unflushed_log' => 'cs',
'log_bytes_flushed' => 'ct',
'log_bytes_written' => 'cu',
'relay_log_space' => 'cv',
'binlog_cache_size' => 'cw',
'Binlog_cache_disk_use' => 'cx',
'Binlog_cache_use' => 'cy',
'binary_log_space' => 'cz',
'innodb_locked_tables' => 'd0',
'innodb_lock_structs' => 'd1',
'State_closing_tables' => 'd2',
'State_copying_to_tmp_table' => 'd3',
'State_end' => 'd4',
'State_freeing_items' => 'd5',
'State_init' => 'd6',
'State_locked' => 'd7',
'State_login' => 'd8',
'State_preparing' => 'd9',
'State_reading_from_net' => 'da',
'State_sending_data' => 'db',
'State_sorting_result' => 'dc',
'State_statistics' => 'dd',
'State_updating' => 'de',
'State_writing_to_net' => 'df',
'State_none' => 'dg',
'State_other' => 'dh',
'Handler_commit' => 'di',
'Handler_delete' => 'dj',
'Handler_discover' => 'dk',
'Handler_prepare' => 'dl',
'Handler_read_first' => 'dm',
'Handler_read_key' => 'dn',
'Handler_read_next' => 'do',
'Handler_read_prev' => 'dp',
'Handler_read_rnd' => 'dq',
'Handler_read_rnd_next' => 'dr',
'Handler_rollback' => 'ds',
'Handler_savepoint' => 'dt',
'Handler_savepoint_rollback' => 'du',
'Handler_update' => 'dv',
'Handler_write' => 'dw',
# Some InnoDB stats added later...
'innodb_tables_in_use' => 'dx',
'innodb_lock_wait_secs' => 'dy',
'hash_index_cells_total' => 'dz',
'hash_index_cells_used' => 'e0',
'total_mem_alloc' => 'e1',
'additional_pool_alloc' => 'e2',
'uncheckpointed_bytes' => 'e3',
'ibuf_used_cells' => 'e4',
'ibuf_free_cells' => 'e5',
'ibuf_cell_count' => 'e6',
'adaptive_hash_memory' => 'e7',
'page_hash_memory' => 'e8',
'dictionary_cache_memory' => 'e9',
'file_system_memory' => 'ea',
'lock_system_memory' => 'eb',
'recovery_system_memory' => 'ec',
'thread_hash_memory' => 'ed',
'innodb_sem_waits' => 'ee',
'innodb_sem_wait_time_ms' => 'ef',
'Key_buf_bytes_unflushed' => 'eg',
'Key_buf_bytes_used' => 'eh',
'key_buffer_size' => 'ei',
'Innodb_row_lock_time' => 'ej',
'Innodb_row_lock_waits' => 'ek',
'Query_time_count_00' => 'el',
'Query_time_count_01' => 'em',
'Query_time_count_02' => 'en',
'Query_time_count_03' => 'eo',
'Query_time_count_04' => 'ep',
'Query_time_count_05' => 'eq',
'Query_time_count_06' => 'er',
'Query_time_count_07' => 'es',
'Query_time_count_08' => 'et',
'Query_time_count_09' => 'eu',
'Query_time_count_10' => 'ev',
'Query_time_count_11' => 'ew',
'Query_time_count_12' => 'ex',
'Query_time_count_13' => 'ey',
'Query_time_total_00' => 'ez',
'Query_time_total_01' => 'fa',
'Query_time_total_02' => 'fb',
'Query_time_total_03' => 'fc',
'Query_time_total_04' => 'fd',
'Query_time_total_05' => 'fe',
'Query_time_total_06' => 'ff',
'Query_time_total_07' => 'fg',
'Query_time_total_08' => 'fh',
'Query_time_total_09' => 'fi',
'Query_time_total_10' => 'fj',
'Query_time_total_11' => 'fk',
'Query_time_total_12' => 'fl',
'Query_time_total_13' => 'fm',
'Key_read_requests' => 'gg',
'Key_reads' => 'gh',
'Key_write_requests' => 'gi',
'Key_writes' => 'gj',
'history_list' => 'gk',
'innodb_transactions' => 'gl',
'read_views' => 'gm',
'current_transactions' => 'gn',
'locked_transactions' => 'go',
'active_transactions' => 'gp',
'pool_size' => 'gq',
'free_pages' => 'gr',
'database_pages' => 'gs',
'modified_pages' => 'gt',
'pages_read' => 'gu',
'pages_created' => 'gv',
'pages_written' => 'gw',
'file_fsyncs' => 'gx',
'file_reads' => 'gy',
'file_writes' => 'gz',
'log_writes' => 'hg',
'pending_aio_log_ios' => 'hh',
'pending_aio_sync_ios' => 'hi',
'pending_buf_pool_flushes' => 'hj',
'pending_chkp_writes' => 'hk',
'pending_ibuf_aio_reads' => 'hl',
'pending_log_flushes' => 'hm',
'pending_log_writes' => 'hn',
'pending_normal_aio_reads' => 'ho',
'pending_normal_aio_writes' => 'hp',
'ibuf_inserts' => 'hq',
'ibuf_merged' => 'hr',
'ibuf_merges' => 'hs',
'spin_waits' => 'ht',
'spin_rounds' => 'hu',
'os_waits' => 'hv',
'rows_inserted' => 'hw',
'rows_updated' => 'hx',
'rows_deleted' => 'hy',
'rows_read' => 'hz',
'Table_locks_waited' => 'ig',
'Table_locks_immediate' => 'ih',
'Slow_queries' => 'ii',
'Open_files' => 'ij',
'Open_tables' => 'ik',
'Opened_tables' => 'il',
'innodb_open_files' => 'im',
'open_files_limit' => 'in',
'table_cache' => 'io',
'Aborted_clients' => 'ip',
'Aborted_connects' => 'iq',
'Max_used_connections' => 'ir',
'Slow_launch_threads' => 'is',
'Threads_cached' => 'it',
'Threads_connected' => 'iu',
'Threads_created' => 'iv',
'Threads_running' => 'iw',
'max_connections' => 'ix',
'thread_cache_size' => 'iy',
'Connections' => 'iz',
'slave_running' => 'jg',
'slave_stopped' => 'jh',
'Slave_retried_transactions' => 'ji',
'slave_lag' => 'jj',
'Slave_open_temp_tables' => 'jk',
'Qcache_free_blocks' => 'jl',
'Qcache_free_memory' => 'jm',
'Qcache_hits' => 'jn',
'Qcache_inserts' => 'jo',
'Qcache_lowmem_prunes' => 'jp',
'Qcache_not_cached' => 'jq',
'Qcache_queries_in_cache' => 'jr',
'Qcache_total_blocks' => 'js',
'query_cache_size' => 'jt',
'Questions' => 'ju',
'Com_update' => 'jv',
'Com_insert' => 'jw',
'Com_select' => 'jx',
'Com_delete' => 'jy',
'Com_replace' => 'jz',
'Com_load' => 'kg',
'Com_update_multi' => 'kh',
'Com_insert_select' => 'ki',
'Com_delete_multi' => 'kj',
'Com_replace_select' => 'kk',
'Select_full_join' => 'kl',
'Select_full_range_join' => 'km',
'Select_range' => 'kn',
'Select_range_check' => 'ko',
'Select_scan' => 'kp',
'Sort_merge_passes' => 'kq',
'Sort_range' => 'kr',
'Sort_rows' => 'ks',
'Sort_scan' => 'kt',
'Created_tmp_tables' => 'ku',
'Created_tmp_disk_tables' => 'kv',
'Created_tmp_files' => 'kw',
'Bytes_sent' => 'kx',
'Bytes_received' => 'ky',
'innodb_log_buffer_size' => 'kz',
'unflushed_log' => 'lg',
'log_bytes_flushed' => 'lh',
'log_bytes_written' => 'li',
'relay_log_space' => 'lj',
'binlog_cache_size' => 'lk',
'Binlog_cache_disk_use' => 'll',
'Binlog_cache_use' => 'lm',
'binary_log_space' => 'ln',
'innodb_locked_tables' => 'lo',
'innodb_lock_structs' => 'lp',
'State_closing_tables' => 'lq',
'State_copying_to_tmp_table' => 'lr',
'State_end' => 'ls',
'State_freeing_items' => 'lt',
'State_init' => 'lu',
'State_locked' => 'lv',
'State_login' => 'lw',
'State_preparing' => 'lx',
'State_reading_from_net' => 'ly',
'State_sending_data' => 'lz',
'State_sorting_result' => 'mg',
'State_statistics' => 'mh',
'State_updating' => 'mi',
'State_writing_to_net' => 'mj',
'State_none' => 'mk',
'State_other' => 'ml',
'Handler_commit' => 'mm',
'Handler_delete' => 'mn',
'Handler_discover' => 'mo',
'Handler_prepare' => 'mp',
'Handler_read_first' => 'mq',
'Handler_read_key' => 'mr',
'Handler_read_next' => 'ms',
'Handler_read_prev' => 'mt',
'Handler_read_rnd' => 'mu',
'Handler_read_rnd_next' => 'mv',
'Handler_rollback' => 'mw',
'Handler_savepoint' => 'mx',
'Handler_savepoint_rollback' => 'my',
'Handler_update' => 'mz',
'Handler_write' => 'ng',
'innodb_tables_in_use' => 'nh',
'innodb_lock_wait_secs' => 'ni',
'hash_index_cells_total' => 'nj',
'hash_index_cells_used' => 'nk',
'total_mem_alloc' => 'nl',
'additional_pool_alloc' => 'nm',
'uncheckpointed_bytes' => 'nn',
'ibuf_used_cells' => 'no',
'ibuf_free_cells' => 'np',
'ibuf_cell_count' => 'nq',
'adaptive_hash_memory' => 'nr',
'page_hash_memory' => 'ns',
'dictionary_cache_memory' => 'nt',
'file_system_memory' => 'nu',
'lock_system_memory' => 'nv',
'recovery_system_memory' => 'nw',
'thread_hash_memory' => 'nx',
'innodb_sem_waits' => 'ny',
'innodb_sem_wait_time_ms' => 'nz',
'Key_buf_bytes_unflushed' => 'og',
'Key_buf_bytes_used' => 'oh',
'key_buffer_size' => 'oi',
'Innodb_row_lock_time' => 'oj',
'Innodb_row_lock_waits' => 'ok',
'Query_time_count_00' => 'ol',
'Query_time_count_01' => 'om',
'Query_time_count_02' => 'on',
'Query_time_count_03' => 'oo',
'Query_time_count_04' => 'op',
'Query_time_count_05' => 'oq',
'Query_time_count_06' => 'or',
'Query_time_count_07' => 'os',
'Query_time_count_08' => 'ot',
'Query_time_count_09' => 'ou',
'Query_time_count_10' => 'ov',
'Query_time_count_11' => 'ow',
'Query_time_count_12' => 'ox',
'Query_time_count_13' => 'oy',
'Query_time_total_00' => 'oz',
'Query_time_total_01' => 'pg',
'Query_time_total_02' => 'ph',
'Query_time_total_03' => 'pi',
'Query_time_total_04' => 'pj',
'Query_time_total_05' => 'pk',
'Query_time_total_06' => 'pl',
'Query_time_total_07' => 'pm',
'Query_time_total_08' => 'pn',
'Query_time_total_09' => 'po',
'Query_time_total_10' => 'pp',
'Query_time_total_11' => 'pq',
'Query_time_total_12' => 'pr',
'Query_time_total_13' => 'ps',
'wsrep_replicated_bytes' => 'pt',
'wsrep_received_bytes' => 'pu',
'wsrep_replicated' => 'pv',
'wsrep_received' => 'pw',
'wsrep_local_cert_failures' => 'px',
'wsrep_local_bf_aborts' => 'py',
'wsrep_local_send_queue' => 'pz',
'wsrep_local_recv_queue' => 'qg',
'wsrep_cluster_size' => 'qh',
'wsrep_cert_deps_distance' => 'qi',
'wsrep_apply_window' => 'qj',
'wsrep_commit_window' => 'qk',
'wsrep_flow_control_paused' => 'ql',
'wsrep_flow_control_sent' => 'qm',
'wsrep_flow_control_recv' => 'qn',
'pool_reads' => 'qo',
'pool_read_requests' => 'qp',
);
# Return the output.
@ -846,13 +909,26 @@ function get_innodb_array($text) {
$results['spin_rounds'][] = to_int($row[5]);
$results['os_waits'][] = to_int($row[8]);
}
elseif (strpos($line, 'RW-shared spins') === 0 ) {
elseif (strpos($line, 'RW-shared spins') === 0
&& strpos($line, ';') > 0 ) {
# RW-shared spins 3859028, OS waits 2100750; RW-excl spins 4641946, OS waits 1530310
$results['spin_waits'][] = to_int($row[2]);
$results['spin_waits'][] = to_int($row[8]);
$results['os_waits'][] = to_int($row[5]);
$results['os_waits'][] = to_int($row[11]);
}
elseif (strpos($line, 'RW-shared spins') === 0 && strpos($line, '; RW-excl spins') === FALSE) {
# Post 5.5.17 SHOW ENGINE INNODB STATUS syntax
# RW-shared spins 604733, rounds 8107431, OS waits 241268
$results['spin_waits'][] = to_int($row[2]);
$results['os_waits'][] = to_int($row[7]);
}
elseif (strpos($line, 'RW-excl spins') === 0) {
# Post 5.5.17 SHOW ENGINE INNODB STATUS syntax
# RW-excl spins 604733, rounds 8107431, OS waits 241268
$results['spin_waits'][] = to_int($row[2]);
$results['os_waits'][] = to_int($row[7]);
}
elseif (strpos($line, 'seconds the semaphore:') > 0) {
# --Thread 907205 has waited at handler/ha_innodb.cc line 7156 for 1.00 seconds the semaphore:
increment($results, 'innodb_sem_waits', 1);
@ -866,7 +942,8 @@ function get_innodb_array($text) {
# transactions
# Trx id counter 0 1170664159
# Trx id counter 861B144C
$results['innodb_transactions'] = make_bigint($row[3], $row[4]);
$results['innodb_transactions'] = make_bigint(
$row[3], (isset($row[4]) ? $row[4] : null));
$txn_seen = TRUE;
}
elseif ( strpos($line, 'Purge done for trx') === 0 ) {
@ -952,6 +1029,16 @@ function get_innodb_array($text) {
$results['ibuf_used_cells'] = to_int($row[2]);
$results['ibuf_free_cells'] = to_int($row[6]);
$results['ibuf_cell_count'] = to_int($row[9]);
if (strpos($line, 'merges')) {
$results['ibuf_merges'] = to_int($row[10]);
}
}
elseif (strpos($line, ', delete mark ') > 0 && strpos($prev_line, 'merged operations:') === 0 ) {
# Output of show engine innodb status has changed in 5.5
# merged operations:
# insert 593983, delete mark 387006, delete 73092
$results['ibuf_inserts'] = to_int($row[1]);
$results['ibuf_merged'] = to_int($row[1]) + to_int($row[4]) + to_int($row[6]);
}
elseif (strpos($line, ' merged recs, ') > 0 ) {
# 19817685 inserts, 19817684 merged recs, 3552620 merges
@ -1007,8 +1094,9 @@ function get_innodb_array($text) {
}
# BUFFER POOL AND MEMORY
elseif (strpos($line, "Total memory allocated") === 0 ) {
elseif (strpos($line, "Total memory allocated") === 0 && strpos($line, "in additional pool allocated") > 0 ) {
# Total memory allocated 29642194944; in additional pool allocated 0
# Total memory allocated by read views 96
$results['total_mem_alloc'] = to_int($row[3]);
$results['additional_pool_alloc'] = to_int($row[8]);
}
@ -1088,6 +1176,7 @@ function get_innodb_array($text) {
$results['queries_inside'] = to_int($row[0]);
$results['queries_queued'] = to_int($row[4]);
}
$prev_line = $line;
}
foreach ( array('spin_waits', 'spin_rounds', 'os_waits') as $key ) {
@ -1144,23 +1233,29 @@ function to_int ( $str ) {
}
# ============================================================================
# Wrap mysql_query in error-handling, and instead of returning the result,
# Wrap mysqli_query in error-handling, and instead of returning the result,
# return an array of arrays in the result.
# ============================================================================
function run_query($sql, $conn) {
global $debug;
debug($sql);
$result = @mysql_query($sql, $conn);
if ( $debug ) {
$error = @mysql_error($conn);
$result = @mysqli_query($conn, $sql);
if ( $debug && strpos($sql, 'SHOW SLAVE STATUS ') === false ) {
$error = @mysqli_error($conn);
if ( $error ) {
debug(array($sql, $error));
die("SQLERR $error in $sql");
}
}
$array = array();
while ( $row = @mysql_fetch_array($result) ) {
$array[] = $row;
$count = @mysqli_num_rows($result);
if ( $count > 10000 ) {
debug('Abnormal number of rows returned: ' . $count);
}
else {
while ( $row = @mysqli_fetch_array($result) ) {
$array[] = $row;
}
}
debug(array($sql, $array));
return $array;
@ -1268,7 +1363,7 @@ function debug($val) {
if ( !count($calls) ) {
$calls[] = "at $file:$line";
}
fwrite($fp, date('Y-m-d h:i:s') . ' ' . implode(' <- ', $calls));
fwrite($fp, date('Y-m-d H:i:s') . ' ' . implode(' <- ', $calls));
fwrite($fp, "\n" . var_export($val, TRUE) . "\n");
fclose($fp);
}
@ -1278,4 +1373,3 @@ function debug($val) {
}
}
?>

7
bin/swap_enabled.sh Normal file
View File

@ -0,0 +1,7 @@
#!/bin/bash
swap=$(free -m | grep -i swap | awk '{ print $2 }')
if [ "$swap" != "0" ]; then
echo '{"data":[{"{#TOTAL}":"total", "{#FREE}":"free", "{#PFREE}":"pfree", "{#PUSED}":"pused" } ]}'
fi

View File

@ -9,4 +9,10 @@ zabbix ALL=(ALL) NOPASSWD: /opt/dell/srvadmin/bin/omreport
zabbix ALL=(ALL) NOPASSWD: /usr/bin/bcu
zabbix ALL=(ALL) NOPASSWD: /sbin/powermt
zabbix ALL=(ALL) NOPASSWD: /bin/find /var/spool/postfix/ -type f
zabbix ALL=(ALL) NOPASSWD: /usr/sbin/httpd -v
zabbix ALL=(ALL) NOPASSWD: /usr/sbin/dmidecode
zabbix ALL=(ALL) NOPASSWD: /usr/bin/stat
zabbix ALL=(ALL) NOPASSWD: /usr/bin/md5sum
zabbix ALL=(ALL) NOPASSWD: /bin/find /var/lib/mysql/ -type f -printf %p+%s=
zabbix ALL=(ALL) NOPASSWD: /etc/zabbix/bin/haproxy.sh
Defaults:zabbix !requiretty

File diff suppressed because it is too large Load Diff