Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hope to God this is mergeable #58

Open
wants to merge 191 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
191 commits
Select commit Hold shift + click to select a range
2ff1b9b
Update the config::clients class to have the nrpe_command_prefix in t…
Jul 31, 2015
e18b6dd
Add check_sslscan check: checks ssl grade
Aug 6, 2015
b5fa35e
Make sslscan a defined type, so we can include it multiple times on t…
Aug 6, 2015
feb4302
checkssl scan require icinga
Aug 6, 2015
8445a95
Fix typo in checkssl
Aug 6, 2015
d0df1d8
checksslscan: puppet doesnt allow variable replacement
Aug 6, 2015
6a82c45
Checkssl scan needs perl-json package
Aug 6, 2015
f14cecd
Increase check nrpe timeout for checkssl command
Aug 6, 2015
e7b3c34
sslcheck: define a nrpe command that has an increasable timeout
Aug 6, 2015
5af357f
checkssl: more verbose line in icinga gui
Aug 6, 2015
ec1d841
check ssl quality: run check every hour, and add extra perl packages
Aug 6, 2015
3be04b2
fixing additional options
Aug 12, 2015
c3fabab
Bugfix: Gave the ssl check more time before timeout, changed running …
Aug 12, 2015
67fcf27
add the check_cron_logs class refs #15477
Aug 13, 2015
e31e006
Bugfix: Check ssl in a async way
Aug 12, 2015
6e50b2d
fixed a copy past error.
TomRitserveldt Aug 13, 2015
a1bc3cd
Bugfix: Updated the file name to check_ssl.erb
Aug 13, 2015
d91f72a
Bugfix: Added the check in the right place aka files directory
Aug 13, 2015
4bcc559
added fqdn to the check_cron_logs exported resource name
Aug 13, 2015
abd3e2a
fixed the cron_logs.cfg.erb template
Aug 13, 2015
6b9f95d
Bugfix: Added host_url to the check for ssl
Aug 14, 2015
18ceefb
bugfix in the cron_logs.cfg.erb template
Aug 14, 2015
d4583ad
change in sudo permissions required by the checkcronlogs plugins
Aug 14, 2015
e199fac
Bugfix: ssl check
Aug 14, 2015
f8c8ede
Bugfix: check ssl: setup cleanup
Aug 14, 2015
6d3b6ea
Bugfix: Setup check ssl again
Aug 14, 2015
a40adf2
Add option to not to monitor mongo replication
kacerr Aug 18, 2015
8b9568d
Add nrpe command that allows icinga to send 4 parameters
kacerr Aug 31, 2015
3b3496b
bugfix in check_cron_logs.sh
Sep 4, 2015
f3546a2
install and use newer package with nagios plugin
Sep 9, 2015
d13bb98
check_nginx template
TomRitserveldt Sep 16, 2015
0c6c4fa
check nginx
TomRitserveldt Sep 16, 2015
57f7a2e
right sudo perms for nrpe commands
Sep 21, 2015
386d839
add icinga::plugins::checkmysqlclient plugin
Sep 22, 2015
b99e3a0
change variables for mysqlclient corresponding to percona::rights
Sep 22, 2015
5b90f64
fix class/define misconfiguration
Sep 22, 2015
85d85a5
parametrize is the drupal cron check should be run with sudo
Oct 5, 2015
e20b440
allow to ignore cron jobs based on tags, ignore drush by default, as …
Oct 8, 2015
52f87a0
the dns sync check reworked
Oct 27, 2015
682abea
update the dns_sync check
Oct 27, 2015
a0d36f8
rename dns_sync.cfg.erb to dns_sync.sh.erb
Oct 29, 2015
6e52633
remove time limit for dns_sync check, its not using nrpe now, so we d…
Nov 3, 2015
bd30ba3
Do not inherit from icinga, just require it already instantiated in
kacerr Nov 18, 2015
d099672
Manage perl nagios plugin package only if it is not handled yet by other
kacerr Nov 19, 2015
628ffe7
Inherits icinga is necessary, further code relies on some attributes to
kacerr Nov 30, 2015
4d5e2f2
add the 'target' parameter to the checkmysqlclient plugin
Dec 1, 2015
fd81aa6
only use the checkmysql plugin if a password is given refs #18991
Dec 3, 2015
d79426d
turn checksslscan into a passive check refs #15623
Dec 15, 2015
ff98050
fix duplicit declaration
Dec 15, 2015
0c6bcab
fix checksslscan template
Dec 15, 2015
87e2375
add the icinga_host variable to the checksslscan check
Dec 15, 2015
9ef4a81
change service description of the checksslscan check
Dec 15, 2015
52577f0
increase the time range during which the checksslscan check runs
Dec 17, 2015
856a5fc
fix check_cron_logs.sh for centos7, allow check_sslscan to try again …
Dec 23, 2015
b77c1e0
fix notifications_enabled for cron check - we had them permanently di…
Jan 27, 2016
8c6358d
Add command for check-host-alive over ipv4 only
kacerr Feb 5, 2016
a6d95c8
fix the class names below beacuse of future parser ( '-' is not allowed)
Feb 15, 2016
19377bf
fix variable names + remove duplication of variables (future parser)
Feb 15, 2016
2cd1254
Facter returns strings, not numbers
Feb 22, 2016
caf96e6
added livestatus broker_module
Mar 7, 2016
66a472f
Merge branch 'master' of ssh://redmine.inuits.eu:2223/puppetmaster/mo…
Mar 7, 2016
153fa86
undo broker module
Mar 7, 2016
99f1136
added livestatus broker module and parameter to enable this
Mar 7, 2016
8ceb00f
enabled livestatus parameter
Mar 7, 2016
7ab11ce
implementation of scheduling downtimes for all services with notifica…
Mar 8, 2016
f0a1554
Added symlink for pip provider
Mar 17, 2016
b5fdb4b
Make ssl quality configurable, not hardcoded
Mar 17, 2016
2fcfb71
do not install pymongo by pip refs #19428
Mar 21, 2016
0f287c5
fix compatibily with Mongo v3
Mar 21, 2016
7ffa5d6
pass replica_set param to one of the check
Mar 21, 2016
95e07fc
fix wrong replacement of find_one by findOne + fix set_read_preferenc…
Mar 21, 2016
c4658b4
fix the failing first run of check_mongodb.py
Mar 21, 2016
264a484
remove explicit hiera calls from checK_dns_sync
Apr 4, 2016
3f3362b
add plugins for monitoring ES
Apr 6, 2016
15fa787
change default number of expected nodes in es cluster to one
Apr 7, 2016
7d008ff
package checkelasticsearch plugin
birgitcroux Apr 7, 2016
aa52522
run check_puppet as root because of occasional permissions issue refs…
Apr 12, 2016
6299c60
Plugins: Checksslscan: Added "2&>1 >/dev/null" to cron
Apr 18, 2016
a4b70be
Plugin: checkpuppet: Added sudo config to the check
Apr 18, 2016
c67d133
add Author: $SERVICEACKAUTHOR$ to notification e-mail
May 10, 2016
52ef6d5
dns_sync: set 3 seconds timeout for DNS request
May 11, 2016
2c7474b
check cron logs: not alert on service notifications sent to icinga fr…
May 18, 2016
342ffdd
add the check_generic command
May 25, 2016
4dfc7b9
fix parsing with the check_cron_logs check
May 25, 2016
8d3d9e6
check_cron_log.sh: fix typo
May 25, 2016
518f224
checkmysqlclient.pp: fix possible duplicate declaration
Jun 1, 2016
4a69ba0
checkmysqlclient.pp add user to service description
Jun 1, 2016
380c228
add collective-access check refs #22484
Jun 27, 2016
8f35d80
checkcollectiveaccess: fix path to the config file
Jun 27, 2016
d565828
Addes required sudo config
Jul 6, 2016
e24ff19
add checkfileage.pp
Jul 26, 2016
32b31ed
add checkfileage.pp
Aug 2, 2016
b88d873
remove check_zimbra_snapshot.pp
Aug 2, 2016
2b969bf
checkfileage.pp: fix the exported resource name
Aug 3, 2016
00f0002
implement ES checks for LPA application logs refs #22929
Aug 4, 2016
0e9a39c
fix duplication logs in messages
Aug 4, 2016
dd04fb4
disable logging passive checks and external command
Aug 4, 2016
54189c9
remove useless parameter
Aug 4, 2016
8cc3089
fix check_number_of_documents plugin - args wrongly passed
Aug 4, 2016
e04fd2d
puppetize changing icinga user credentials
Aug 8, 2016
520232d
check "15 minutes ago" by default in check_number_of_documents.pp
Aug 9, 2016
35e7cb3
force recursive purge of dirs - fix icinga restart refs #22831
Aug 9, 2016
3c0eba0
adapt the server load thresholds to the processor count
Aug 9, 2016
fe7ba88
increase minimal level for server load
Aug 9, 2016
f555541
fix check_number_of_documents - quote _interval_ parameter
Aug 10, 2016
e7aa35e
add checkrabbitmqsync.pp
Aug 10, 2016
a13e20b
checkrabbitmqsync.pp class > define
Aug 10, 2016
59e07a6
checkrabbitmqsync.pp: inherits > require
Aug 10, 2016
dbc50b1
checkrabbitmqsync.pp: correct the name of the executable file-s
Aug 10, 2016
4a5d33d
remove bacula related stuff - we do not use bacula anymore refs #19441
Aug 11, 2016
c0a1280
mod icinga: increase thresholds of load check for critical
Aug 24, 2016
1311863
update haproxy check refs #23353
Aug 26, 2016
74d4917
checkhaproxy: move exported resources to define refs #23353
Aug 26, 2016
8151ba0
check_haproxy.rb allow first redirect
Aug 26, 2016
a536e61
checkhaproxy - remove unnecessary params
Aug 26, 2016
7f2ca44
haproxy check: fix service name
Aug 26, 2016
798e7a7
haproxy check: fix redirection for ruby 1.8
Aug 26, 2016
3ccb7ef
Ensure python-nagioscheck is installed for the elasticsearch python b…
carroarmato0 Aug 26, 2016
ec77368
haproxy check: fix the number of argument
Aug 26, 2016
2837881
puppet-lint satisfied
Aug 26, 2016
c8bd8ef
Install relevant nagios packages for the various es plugins
carroarmato0 Aug 26, 2016
6b3d5df
check_gluster: do not alert on unsynced entries, monitor split-brain …
Aug 30, 2016
6e5dde6
add IP address duplication check refs #23350
Sep 1, 2016
2065e1b
fix ip_address_duplication_check.sh for boxes with more ifaces refs #…
Sep 1, 2016
de30298
ip_address_duplication_check.sh sent output to icinga, ignore localhost
Sep 1, 2016
260d620
files/ip_address_duplication_check.sh - check only active ifaces
Sep 1, 2016
22d0997
files/ip_address_duplication_check.sh - do not check drac iface
Sep 1, 2016
0c535b5
checkrabbitmqsync: change service description
Sep 5, 2016
224638d
added checkvufwatcher.pp
Sep 14, 2016
a1ef10d
changed check_vufwatcher command
Sep 14, 2016
e36e108
only 1 vufwatcher process allowed
Sep 14, 2016
928aae8
check_rsnapshot.rb: support backup scripts in config file
Sep 15, 2016
1bc5136
nagios-plugins-checkcrm packae replaced by nagios-plugins-crm refs #2…
Sep 22, 2016
7c79f7e
set sudo perm for whhole check_crm file + check constraints refs #23832
Sep 22, 2016
96ca704
make the gluster check work with TB drives refs #24311
Oct 7, 2016
e5eb246
check_gluster.sh: fix substring index
Oct 7, 2016
cccfd40
add check_sshuttle.pp refs #24100
Oct 31, 2016
36c6f8d
check_sshuttle: add subnets param
Nov 3, 2016
3d0656e
testing commit
Nov 3, 2016
3b2ae9f
add the check_tcp_other_host command
Nov 3, 2016
3315af1
check_sshuttle: use check_tcp_other_host instead of check_tcp
Nov 3, 2016
8f42e98
moved checkvufwatcher.pp to profile_vufwatcher
Nov 9, 2016
aa89d42
changed check_interval to 60 minutes for check_cron_log
Nov 10, 2016
095d2a2
add sportoaseOpeningHours definition to get_services_with_workhours.p…
Nov 14, 2016
98a9c13
Revert "add sportoaseOpeningHours definition to get_services_with_wor…
Nov 14, 2016
907fd16
schedule downtimes based on hiera data
Nov 15, 2016
f1fa838
fix in schedule downtime script
Nov 15, 2016
2604834
Revert "fix in schedule downtime script"
Nov 15, 2016
0685804
typo fix
Nov 15, 2016
56346ad
syntax fix get_services_with_workhours.py.erb
Nov 15, 2016
732f70e
layout fix in python script
Nov 15, 2016
73b7140
schedule downtime for hostchecks
Nov 16, 2016
94ebdfa
add check_pgactivity (moved here from profile_pgsql)
Nov 28, 2016
0a52efb
set owner/group of icinga::plugins::checkgraphite + do not export ref…
Dec 1, 2016
daaa54b
do not require ::ntp
Dec 1, 2016
fd6f57e
monitor Mongoreplication only when replica_set is defined refs #25740
Dec 21, 2016
7f78dba
changed icinga.inuits.eu to localhost in sched_down_for_workhours.pp
Jan 5, 2017
d82b870
ensure schedule_downtime_for_workhours file has right ownership
Jan 5, 2017
8e9b4d5
https => http in schedule_downtime_for_workhours
Jan 5, 2017
4ea7740
add checkhttps.pp and checkhttps_certificate.pp
Jan 5, 2017
4c3fa95
checkhttps.pp fix duplicate declaration
Jan 5, 2017
2b28860
fix typo
Jan 5, 2017
a77e79b
make icinga_user en _pass undef in schedule_downtime_for_workhours.pp
Jan 6, 2017
6a09db8
changed date format to something sensebile
Jan 13, 2017
e6b5166
update elasticsearch/check_number_of_documents.sh refs #26676
Jan 19, 2017
899aaf7
mod icinga: update elasticsearch/check_number_of_documents.sh - typos…
Jan 19, 2017
251655d
enable icinga notifications postgres check refs #26372
Jan 26, 2017
7b5dbba
add checkcertexpiry.pp
Jan 26, 2017
f71bc84
fix template for checkcertexpiry.pp
Jan 26, 2017
fc19a74
enable notifiction period in passivecheck refs #26372
Jan 26, 2017
a843e4a
checkcertexpiry.pp: fix inline template
Jan 27, 2017
50f2009
checkcertexpiry.pp: change template
Jan 27, 2017
e1529b6
checkcertexpiry.pp: make the check work with sha1-signed certs, lpa n…
Jan 30, 2017
bd30cfa
checkcertexpiry.pp execute the check with sudo refs #26044
Jan 31, 2017
17db9c4
add alternative to hiera call refs #23109
Jan 31, 2017
6f70c77
check_rsnapshot - work with numbers properly refs #23109
Jan 31, 2017
7fb50f6
remomve sudo declaration from checkcertexpiry.pp
Jan 31, 2017
a3c2cfd
check_rsnapshot.rb - use snapshot_root from config file refs #23109
Jan 31, 2017
2d0ceb3
install nagios-plugins-ssl-cert package for checkcertexpiry.pp refs #…
Feb 17, 2017
c984b94
re-add sudo::conf for checkcertexpiry.pp refs #26044
Feb 17, 2017
83d6ec3
checkelasticsearch.pp: remove the commented-out part using pip refs #…
Feb 21, 2017
abfef62
add checktopologylatency.pp refs #27218
Mar 9, 2017
948953d
fix file name
Mar 9, 2017
4e2d4b8
checksmart.pp - smart_devices is mandatory refs #28075
Mar 21, 2017
39f5bdf
S.M.A.R.T. check with device autodetect refs #28075
Mar 22, 2017
f70b75b
autodetect device type + update check_smart.pl #28075
Mar 22, 2017
f0bdbae
S.M.A.R.T. check with device autodetect - unused variable refs #28075
Mar 22, 2017
8fa9270
S.M.A.R.T - print number of monitoried devices refs #28075
Mar 22, 2017
f4147e4
Fix typo
carroarmato0 Apr 5, 2017
4ca3215
Add monitoring for max_connections
carroarmato0 Apr 5, 2017
333ad18
Use correct value to monitor current mysql connections
carroarmato0 Apr 6, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .puppet-lint.rc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
--no-80chars-check
--no-140chars-check
--no-names_containing_dash-check
--no-class_inherits_from_params_class-check
54 changes: 54 additions & 0 deletions files/check_cron_logs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/sh

LOG_FILE='/var/log/messages'
DATE=$(date --date="24 hours ago" '+%b %-d %H' | sed -r 's/^([a-zA-Z]+) /\1 {1,2}/g')
NAME=$(hostname --short)
CRONS_FAILING=''
IGNORE_TAG='drush|SERVICE NOTIFICATION|SERVICE ALERT'

while getopts ":i:" o; do
case "${o}" in
i)
IGNORE_TAG="("$(echo "${OPTARG}" | sed 's/ /)|(/g')")"
;;
*)
echo "Bad param"
;;
esac
done
shift $((OPTIND-1))


REGEX="("$(echo "$@" | sed 's/ /)|(/g')")"

##By defualt, only logs newer than 24h are checked, let's check if there even are that old logs

if egrep -q "$DATE" /var/log/messages; then
if [ $REGEX != '()' ]; then
CRONS_FAILING=$(cat $LOG_FILE | sed -r "1,/$DATE/d" |egrep "cron .*\[[0-9]+\].*\[error\]" | egrep -v "$IGNORE_TAG" |
sed -r "s/^.*$NAME [^ ]+ ([^ ]* )?cron ([^\[]+).*/\2/g" | sort | uniq | egrep -v $REGEX)
else
CRONS_FAILING=$(cat $LOG_FILE | sed -r "1,/$DATE/d" |egrep "cron .*\[[0-9]+\].*\[error\]" | egrep -v "$IGNORE_TAG" |
sed -r "s/^.*$NAME [^ ]+ ([^ ]* )?cron ([^\[]+).*/\2/g" | sort | uniq)
fi

##if not, we're simply reading the whole file

else
if [ $REGEX != '()' ]; then
CRONS_FAILING=$(cat $LOG_FILE |egrep "cron .*\[[0-9]+\].*\[error\]" | egrep -v "$IGNORE_TAG" |
sed -r "s/^.*$NAME [^ ]+ ([^ ]* )?cron ([^\[]+).*/\2/g" | sort | uniq | egrep -v $REGEX)
else
CRONS_FAILING=$(cat $LOG_FILE |egrep "cron .*\[[0-9]+\].*\[error\]" | egrep -v "$IGNORE_TAG" |
sed -r "s/^.*$NAME [^ ]+ ([^ ]* )?cron ([^\[]+).*/\2/g" | sort | uniq)
fi
fi

if [ -z "$CRONS_FAILING" ]; then
echo "No cron jobs have failed over the past 24 hours."
exit 0
else
echo "Cron jobs that have failed over the past 24 hours: "$CRONS_FAILING
exit 1
fi

16 changes: 5 additions & 11 deletions files/check_gluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,11 @@ VOLUME=$1
ex_stat=OK
BRICKS=$(sudo gluster volume info $VOLUME | grep "Number of Bricks" | cut -f8 -d" ")

# get volume heal status
heal=0
for entries in $(sudo gluster volume heal ${VOLUME} info | awk '/^Number of entries: /{print $4}'); do
if [ "$entries" -gt 0 ]; then
let $((heal+=entries))
fi
done
if [ "$heal" -gt 0 ]; then
errors=("${errors[@]}" "$heal unsynched entries")
if sudo gluster volume heal data info split-brain | grep 'Number of entries in split-brain: [1-9]'; then
errors=("${errors[@]}" "entries in split-brain present!")
fi


# get volume status
bricksfound=0
freegb=9999999
Expand All @@ -122,9 +116,9 @@ sudo gluster volume status $VOLUME detail | while IFS='\n' read line; do
key=${field[@]:0:3}
if [ "${key}" = "Disk Space Free" ]; then
freeunit=${field[@]:4}
free=${freeunit%'GB'}
unit=${freeunit: -2}
free=${freeunit::${#freeunit}-2}
freeconvgb=`echo "($free*1024)" | bc`
unit=${freeunit#$free}
if [ "$unit" = "TB" ]; then
free=$freeconvgb
unit="GB"
Expand Down
169 changes: 109 additions & 60 deletions files/check_haproxy.rb
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
#!/usr/bin/ruby

require "net/http"
# This file is managed by puppet.
#
# Source of this script: https://github.com/benprew/nagios-checks
# which actually contains the changes from this pull request
# https://github.com/benprew/nagios-checks/pull/8/commits

require 'optparse'
require 'open-uri'
require 'ostruct'
require 'csv'
require 'openssl'


OK = 0
WARNING = 1
CRITICAL = 2
UNKNOWN = 3

# allows https with invalid certificate on ruby 1.8+
#
# src: also://snippets.aktagon.com/snippets/370-hack-for-using-openuri-with-ssl
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE

status = ['OK', 'WARN', 'CRIT', 'UNKN']

@proxies = []
@errors = []
@perfdata = []
exit_code = OK

options = OpenStruct.new
Expand All @@ -28,22 +41,10 @@

# Required arguments
opts.on("-u", "--url URL", "Statistics URL to check (eg. http://demo.1wt.eu/)") do |v|
options.url = v+":18080"
# puts options.url
options.url = v
options.url += "/;csv" unless options.url =~ /;/
options.url="http://"+options.url

begin
response = Net::HTTP.get_response(URI(options.url));
rescue
puts "Service not running"
exit CRITICAL
end


end


# Optional Arguments
opts.on("-p", "--proxies [PROXIES]", "Only check these proxies (eg. proxy1,proxy2,proxylive)") do |v|
options.proxies = v.split(/,/)
Expand Down Expand Up @@ -97,54 +98,103 @@
exit UNKNOWN
end

open(options.url, :http_basic_authentication => [options.user, options.password]) do |f|
f.each do |line|

if line =~ /^# /
HAPROXY_COLUMN_NAMES = line[2..-1].split(',')
next
elsif ! defined? HAPROXY_COLUMN_NAMES
puts "ERROR: CSV header is missing"
exit UNKNOWN
end
tries = 2

begin
f = open(options.url, :http_basic_authentication => [options.user, options.password])
rescue OpenURI::HTTPError => e
puts "ERROR: #{e.message}"
exit CRITICAL
rescue Errno::ECONNREFUSED => e
puts "ERROR: #{e.message}"
exit CRITICAL
rescue Exception => e
if e.message =~ /redirection forbidden/
options.url = e.message.gsub(/.*-> (.*)/, '\1') # extract redirect URL
retry if (tries -= 1) > 0
raise
else
exit UNKNOWN
end
end

row = HAPROXY_COLUMN_NAMES.zip(CSV.parse(line)[0]).reduce({}) { |hash, val| hash.merge({val[0] => val[1]}) }

next unless options.proxies.empty? || options.proxies.include?(row['pxname'])
next if row['pxname'] == 'statistics'

role = row['act'].to_i > 0 ? 'active ' : (row['bck'].to_i > 0 ? 'backup ' : '')
message = sprintf("%s: %s %s%s", row['pxname'], row['status'], role, row['svname'])

if %w(FRONTEND BACKEND).include? row['svname']
if options.critical && row['scur'].to_i * 100 >= options.critical.to_i * row['slim'].to_i
@errors << sprintf("%s has too many sessions (%s/%s) on %s proxy",
row['svname'],
row['scur'],
row['slim'],
row['pxname'])
exit_code = CRITICAL
elsif options.warning && row['scur'].to_i * 100 >= options.warning.to_i * row['slim'].to_i
@errors << sprintf("%s has too many sessions (%s/%s) on %s proxy",
row['svname'],
row['scur'],
row['slim'],
row['pxname'])
exit_code = WARNING if exit_code == OK || exit_code == UNKNOWN
end

if row['status'] != 'OPEN' && row['status'] != 'UP'
@errors << message
exit_code = CRITICAL
end
f.each do |line|

if line =~ /^# /
HAPROXY_COLUMN_NAMES = line[2..-1].split(',')
next
elsif ! defined? HAPROXY_COLUMN_NAMES
puts "ERROR: CSV header is missing"
exit UNKNOWN
end

elsif row['status'] != 'no check'
@proxies << message
row = HAPROXY_COLUMN_NAMES.zip(CSV.parse(line)[0]).reduce({}) { |hash, val| hash.merge({val[0] => val[1]}) }

if row['status'] != 'UP'
@errors << message
exit_code = WARNING if exit_code == OK || exit_code == UNKNOWN
next unless options.proxies.empty? || options.proxies.include?(row['pxname'])
next if ['statistics', 'admin_stats', 'stats'].include? row['pxname']

role = row['act'].to_i > 0 ? 'active ' : (row['bck'].to_i > 0 ? 'backup ' : '')
message = sprintf("%s: %s %s%s", row['pxname'], row['status'], role, row['svname'])
perf_id = "#{row['pxname']}".downcase

if row['svname'] == 'FRONTEND'
if row['slim'].to_i == 0
session_percent_usage = 0
else
session_percent_usage = row['scur'].to_i * 100 / row['slim'].to_i
end
@perfdata << "#{perf_id}_sessions=#{session_percent_usage}%;#{options.warning ? options.warning : ""};#{options.critical ? options.critical : ""};;"
@perfdata << "#{perf_id}_rate=#{row['rate']};;;;#{row['rate_max']}"
if options.critical && session_percent_usage > options.critical.to_i
@errors << sprintf("%s has way too many sessions (%s/%s) on %s proxy",
row['svname'],
row['scur'],
row['slim'],
row['pxname'])
exit_code = CRITICAL
elsif options.warning && session_percent_usage > options.warning.to_i
@errors << sprintf("%s has too many sessions (%s/%s) on %s proxy",
row['svname'],
row['scur'],
row['slim'],
row['pxname'])
exit_code = WARNING if exit_code == OK || exit_code == UNKNOWN
end

if row['status'] != 'OPEN' && row['status'] != 'UP'
@errors << message
exit_code = CRITICAL
end

elsif row['svname'] == 'BACKEND'
# It has no point to check sessions number for backends, against the alert limits,
# as the SLIM number is actually coming from the "fullconn" parameter.
# So we just collect perfdata. See the following url for more info:
# http://comments.gmane.org/gmane.comp.web.haproxy/9715
current_sessions = row['scur'].to_i
@perfdata << "#{perf_id}_sessions=#{current_sessions};;;;"
@perfdata << "#{perf_id}_rate=#{row['rate']};;;;#{row['rate_max']}"
if row['status'] != 'OPEN' && row['status'] != 'UP'
@errors << message
exit_code = CRITICAL
end

elsif row['status'] != 'no check'
@proxies << message

if row['status'] != 'UP'
@errors << message
exit_code = WARNING if exit_code == OK || exit_code == UNKNOWN
else
if row['slim'].to_i == 0
session_percent_usage = 0
else
session_percent_usage = row['scur'].to_i * 100 / row['slim'].to_i
end
@perfdata << "#{perf_id}-#{row['svname']}_sessions=#{session_percent_usage}%;;;;"
@perfdata << "#{perf_id}-#{row['svname']}_rate=#{row['rate']};;;;#{row['rate_max']}"
end
end
end
Expand All @@ -158,25 +208,24 @@
exit_code = UNKNOWN if exit_code == OK
end

puts "HAPROXY " + status[exit_code] + ": " + @errors.join('; ')
puts "HAPROXY " + status[exit_code] + ": " + @errors.join('; ') + "|" + @perfdata.join(" ")
puts @proxies

exit exit_code

=begin
Copyright (C) 2013 Ben Prew
Copyright (C) 2013 Mark Ruys, Peercode <[email protected]>

Copyright (C) 2015 Hector Sanjuan. Nugg.ad <[email protected]>
Copyright (C) 2015 Roger Torrentsgeneros <[email protected]>
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 3 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, see <http://www.gnu.org/licenses/>.
=end
Loading