diff --git a/.puppet-lint.rc b/.puppet-lint.rc index 1f2d205..366ec39 100644 --- a/.puppet-lint.rc +++ b/.puppet-lint.rc @@ -1,3 +1,3 @@ ---no-80chars-check +--no-140chars-check --no-names_containing_dash-check --no-class_inherits_from_params_class-check diff --git a/files/check_cron_logs.sh b/files/check_cron_logs.sh new file mode 100644 index 0000000..29543a9 --- /dev/null +++ b/files/check_cron_logs.sh @@ -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 + diff --git a/files/check_gluster.sh b/files/check_gluster.sh index ef75291..49f9f1d 100644 --- a/files/check_gluster.sh +++ b/files/check_gluster.sh @@ -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 @@ -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" diff --git a/files/check_haproxy.rb b/files/check_haproxy.rb old mode 100755 new mode 100644 index a94ea08..6499bcb --- a/files/check_haproxy.rb +++ b/files/check_haproxy.rb @@ -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 @@ -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(/,/) @@ -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 @@ -158,7 +208,7 @@ 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 @@ -166,17 +216,16 @@ =begin Copyright (C) 2013 Ben Prew Copyright (C) 2013 Mark Ruys, Peercode - +Copyright (C) 2015 Hector Sanjuan. Nugg.ad +Copyright (C) 2015 Roger Torrentsgeneros 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 . =end diff --git a/files/check_mongodb.py b/files/check_mongodb.py index 86a88d7..24fc11d 100755 --- a/files/check_mongodb.py +++ b/files/check_mongodb.py @@ -1,7 +1,5 @@ #!/usr/bin/env python -### File managed with puppet ### - # # A MongoDB Nagios check script # @@ -18,6 +16,8 @@ # - @jbraeuer on github # - Dag Stockstad # - @Andor on github +# - Steven Richards - Captainkrtek on github +# - Max Vernimmen - @mvernimmen-CG / @mvernimmen on github # # USAGE # @@ -125,16 +125,16 @@ def main(argv): p = optparse.OptionParser(conflict_handler="resolve", description="This Nagios plugin checks the health of mongodb.") p.add_option('-H', '--host', action='store', type='string', dest='host', default='127.0.0.1', help='The hostname you want to connect to') - p.add_option('-P', '--port', action='store', type='int', dest='port', default=27017, help='The port mongodb is runnung on') + p.add_option('-P', '--port', action='store', type='int', dest='port', default=27017, help='The port mongodb is running on') p.add_option('-u', '--user', action='store', type='string', dest='user', default=None, help='The username you want to login as') p.add_option('-p', '--pass', action='store', type='string', dest='passwd', default=None, help='The password you want to use for that user') - p.add_option('-W', '--warning', action='store', dest='warning', default=None, help='The warning threshold we want to set') - p.add_option('-C', '--critical', action='store', dest='critical', default=None, help='The critical threshold we want to set') + p.add_option('-W', '--warning', action='store', dest='warning', default=None, help='The warning threshold you want to set') + p.add_option('-C', '--critical', action='store', dest='critical', default=None, help='The critical threshold you want to set') p.add_option('-A', '--action', action='store', type='choice', dest='action', default='connect', help='The action you want to take', choices=['connect', 'connections', 'replication_lag', 'replication_lag_percent', 'replset_state', 'memory', 'memory_mapped', 'lock', 'flushing', 'last_flush_time', 'index_miss_ratio', 'databases', 'collections', 'database_size', 'database_indexes', 'collection_indexes', 'collection_size', - 'queues', 'oplog', 'journal_commits_in_wl', 'write_data_files', 'journaled', 'opcounters', 'current_lock', 'replica_primary', 'page_faults', - 'asserts', 'queries_per_second', 'page_faults', 'chunks_balance', 'connect_primary', 'collection_state', 'row_count', 'replset_quorum']) + 'collection_storageSize', 'queues', 'oplog', 'journal_commits_in_wl', 'write_data_files', 'journaled', 'opcounters', 'current_lock', 'replica_primary', + 'page_faults', 'asserts', 'queries_per_second', 'page_faults', 'chunks_balance', 'connect_primary', 'collection_state', 'row_count', 'replset_quorum']) p.add_option('--max-lag', action='store_true', dest='max_lag', default=False, help='Get max replication lag (for replication_lag action only)') p.add_option('--mapped-memory', action='store_true', dest='mapped_memory', default=False, help='Get mapped memory instead of resident (if resident memory can not be read)') p.add_option('-D', '--perf-data', action='store_true', dest='perf_data', default=False, help='Enable output of Nagios performance data') @@ -145,6 +145,8 @@ def main(argv): p.add_option('-q', '--querytype', action='store', dest='query_type', default='query', help='The query type to check [query|insert|update|delete|getmore|command] from queries_per_second') p.add_option('-c', '--collection', action='store', dest='collection', default='admin', help='Specify the collection to check') p.add_option('-T', '--time', action='store', type='int', dest='sample_time', default=1, help='Time used to sample number of pages faults') + p.add_option('-M', '--mongoversion', action='store', type='choice', dest='mongo_version', default='2', help='The MongoDB version you are talking with, either 2 or 3', + choices=['2','3']) options, arguments = p.parse_args() host = options.host @@ -164,18 +166,13 @@ def main(argv): action = options.action perf_data = options.perf_data max_lag = options.max_lag + mongo_version = options.mongo_version database = options.database ssl = options.ssl replicaset = options.replicaset - if action == 'replica_primary': - err_f, con_f = mongo_connect(host, port, ssl, user, passwd) - if err_f != 0: - return err_f - if not replicaset: - replicaset = con_f.admin.command("replSetGetStatus")['set'] - if not replicaset: - return "replicaset must be passed in when using replica_primary check" + if action == 'replica_primary' and replicaset is None: + return "replicaset must be passed in when using replica_primary check" elif not action == 'replica_primary' and replicaset: return "passing a replicaset while not checking replica_primary does not work" @@ -199,13 +196,13 @@ def main(argv): elif action == "replset_state": return check_replset_state(con, perf_data, warning, critical) elif action == "memory": - return check_memory(con, warning, critical, perf_data, options.mapped_memory) + return check_memory(con, warning, critical, perf_data, options.mapped_memory, host) elif action == "memory_mapped": return check_memory_mapped(con, warning, critical, perf_data) elif action == "queues": return check_queues(con, warning, critical, perf_data) elif action == "lock": - return check_lock(con, warning, critical, perf_data) + return check_lock(con, warning, critical, perf_data, mongo_version) elif action == "current_lock": return check_current_lock(con, host, warning, critical, perf_data) elif action == "flushing": @@ -233,6 +230,8 @@ def main(argv): return check_collection_indexes(con, database, collection, warning, critical, perf_data) elif action == "collection_size": return check_collection_size(con, database, collection, warning, critical, perf_data) + elif action == "collection_storageSize": + return check_collection_storageSize(con, database, collection, warning, critical, perf_data) elif action == "journaled": return check_journaled(con, warning, critical, perf_data) elif action == "write_data_files": @@ -242,9 +241,9 @@ def main(argv): elif action == "asserts": return check_asserts(con, host, warning, critical, perf_data) elif action == "replica_primary": - return check_replica_primary(con, host, warning, critical, perf_data, replicaset) + return check_replica_primary(con, host, warning, critical, perf_data, replicaset, mongo_version) elif action == "queries_per_second": - return check_queries_per_second(con, query_type, warning, critical, perf_data) + return check_queries_per_second(con, query_type, warning, critical, perf_data, mongo_version) elif action == "page_faults": check_page_faults(con, sample_time, warning, critical, perf_data) elif action == "chunks_balance": @@ -307,9 +306,14 @@ def exit_with_general_critical(e): def set_read_preference(db): - if pymongo.version >= "2.1": - db.read_preference = pymongo.ReadPreference.SECONDARY - + #if pymongo.version >= "2.2": + # pymongo.read_preferences.Secondary + #else: + # db.read_preference = pymongo.ReadPreference.SECONDARY + # I haven't found the reason why it does not work. Anyway this dirty fix works + # The clue is probalby in older version of pymongo (installed from Centos repo instead + # of by pip) + db.read_preference = pymongo.ReadPreference.SECONDARY def check_connect(host, port, warning, critical, perf_data, user, passwd, conn_time): warning = warning or 3 @@ -343,6 +347,10 @@ def check_connections(con, warning, critical, perf_data): def check_rep_lag(con, host, port, warning, critical, percent, perf_data, max_lag, user, passwd): # Get mongo to tell us replica set member name when connecting locally if "127.0.0.1" == host: + if not "me" in con.admin.command("ismaster","1").keys(): + print "OK - This is not replicated MongoDB" + sys.exit(3) + host = con.admin.command("ismaster","1")["me"].split(':')[0] if percent: @@ -360,7 +368,7 @@ def check_rep_lag(con, host, port, warning, critical, percent, perf_data, max_la try: rs_status = con.admin.command("replSetGetStatus") except pymongo.errors.OperationFailure, e: - if e.code == None and str(e).find('failed: not running with --replSet"'): + if ((e.code == None and str(e).find('failed: not running with --replSet"')) or (e.code == 76 and str(e).find('not running with --replSet"'))): print "OK - Not running with replSet" return 0 @@ -383,7 +391,7 @@ def check_rep_lag(con, host, port, warning, critical, percent, perf_data, max_la for member in rs_status["members"]: if member["stateStr"] == "PRIMARY": primary_node = member - if member["name"].split(':')[0] == host and int(member["name"].split(':')[1]) == port: + if member.get('self') == True: host_node = member # Check if we're in the middle of an election and don't have a primary @@ -504,13 +512,35 @@ def check_rep_lag(con, host, port, warning, critical, percent, perf_data, max_la except Exception, e: return exit_with_general_critical(e) +# +# Check the memory usage of mongo. Alerting on this may be hard to get right +# because it'll try to get as much memory as it can. And that's probably +# a good thing. +# +def check_memory(con, warning, critical, perf_data, mapped_memory, host): + # Get the total system memory of this system (This is totally bogus if you + # are running this command remotely) and calculate based on that how much + # memory used by Mongodb is ok or not. + meminfo = open('/proc/meminfo').read() + matched = re.search(r'^MemTotal:\s+(\d+)', meminfo) + if matched: + mem_total_kB = int(matched.groups()[0]) + + if host != "127.0.0.1" and not warning: + # Running remotely and value was not set by user, use hardcoded value + warning = 12 + else: + # running locally or user provided value + warning = warning or (mem_total_kB * 0.8) / 1024.0 / 1024.0 + + if host != "127.0.0.1" and not critical: + critical = 16 + else: + critical = critical or (mem_total_kB * 0.9) / 1024.0 / 1024.0 + + # debugging + #print "mem total: {0}kb, warn: {1}GB, crit: {2}GB".format(mem_total_kB,warning, critical) -def check_memory(con, warning, critical, perf_data, mapped_memory): - # - # These thresholds are basically meaningless, and must be customized to your system's ram - # - warning = warning or 8 - critical = critical or 16 try: data = get_server_status(con) if not data['mem']['supported'] and not mapped_memory: @@ -581,7 +611,7 @@ def check_memory_mapped(con, warning, critical, perf_data): message += " %.2fGB mappedWithJournal" % mem_mapped_journal except: mem_mapped_journal = 0 - message += performance_data(perf_data, [("%.2f" % mem_mapped, "memory_mapped"), ("%.2f" % mem_mapped_journal, "mappedWithJournal")]) + message += performance_data(perf_data, [("%.2f" % mem_mapped, "memory_mapped", warning, critical), ("%.2f" % mem_mapped_journal, "mappedWithJournal")]) if not mem_mapped == -1: return check_levels(mem_mapped, warning, critical, message) @@ -593,21 +623,33 @@ def check_memory_mapped(con, warning, critical, perf_data): return exit_with_general_critical(e) -def check_lock(con, warning, critical, perf_data): +# +# Return the percentage of the time there was a global Lock +# +def check_lock(con, warning, critical, perf_data, mongo_version): warning = warning or 10 critical = critical or 30 - try: - data = get_server_status(con) - # - # calculate percentage - # - lock_percentage = float(data['globalLock']['lockTime']) / float(data['globalLock']['totalTime']) * 100 - message = "Lock Percentage: %.2f%%" % lock_percentage - message += performance_data(perf_data, [("%.2f" % lock_percentage, "lock_percentage", warning, critical)]) - return check_levels(lock_percentage, warning, critical, message) - - except Exception, e: - return exit_with_general_critical(e) + if mongo_version == "2": + try: + data = get_server_status(con) + lockTime = data['globalLock']['lockTime'] + totalTime = data['globalLock']['totalTime'] + # + # calculate percentage + # + if lockTime > totalTime: + lock_percentage = 0.00 + else: + lock_percentage = float(lockTime) / float(totalTime) * 100 + message = "Lock Percentage: %.2f%%" % lock_percentage + message += performance_data(perf_data, [("%.2f" % lock_percentage, "lock_percentage", warning, critical)]) + return check_levels(lock_percentage, warning, critical, message) + except Exception, e: + print "Couldn't get globalLock lockTime info from mongo, are you sure you're not using version 3? See the -M option." + return exit_with_general_critical(e) + else: + print "FAIL - Mongo3 doesn't report on global locks" + return 1 def check_flushing(con, warning, critical, avg, perf_data): @@ -710,7 +752,7 @@ def check_replset_state(con, perf_data, warning="", critical=""): data = con.admin.command(son.SON([('replSetGetStatus', 1)])) state = int(data['myState']) except pymongo.errors.OperationFailure, e: - if e.code == None and str(e).find('failed: not running with --replSet"'): + if ((e.code == None and str(e).find('failed: not running with --replSet"')) or (e.code == 76 and str(e).find('not running with --replSet"'))): state = -1 if state == 8: @@ -921,7 +963,32 @@ def check_collection_size(con, database, collection, warning, critical, perf_dat except Exception, e: return exit_with_general_critical(e) -def check_queries_per_second(con, query_type, warning, critical, perf_data): + +def check_collection_storageSize(con, database, collection, warning, critical, perf_data): + warning = warning or 100 + critical = critical or 1000 + perfdata = "" + try: + set_read_preference(con.admin) + data = con[database].command('collstats', collection) + storageSize = data['storageSize'] / 1024 / 1024 + if perf_data: + perfdata += " | collection_storageSize=%i;%i;%i" % (storageSize, warning, critical) + + if storageSize >= critical: + print "CRITICAL - %s.%s storageSize: %.0f MB %s" % (database, collection, storageSize, perfdata) + return 2 + elif storageSize >= warning: + print "WARNING - %s.%s storageSize: %.0f MB %s" % (database, collection, storageSize, perfdata) + return 1 + else: + print "OK - %s.%s storageSize: %.0f MB %s" % (database, collection, storageSize, perfdata) + return 0 + except Exception, e: + return exit_with_general_critical(e) + + +def check_queries_per_second(con, query_type, warning, critical, perf_data, mongo_version): warning = warning or 250 critical = critical or 500 @@ -945,7 +1012,10 @@ def check_queries_per_second(con, query_type, warning, critical, perf_data): query_per_sec = float(diff_query) / float(diff_ts) # update the count now - db.nagios_check.update({u'_id': last_count['_id']}, {'$set': {"data.%s" % query_type: {'count': num, 'ts': int(time.time())}}}) + if mongo_version == "2": + db.nagios_check.update({u'_id': last_count['_id']}, {'$set': {"data.%s" % query_type: {'count': num, 'ts': int(time.time())}}}) + else: + db.nagios_check.updateOne({u'_id': last_count['_id']}, {'$set': {"data.%s" % query_type: {'count': num, 'ts': int(time.time())}}}) message = "Queries / Sec: %f" % query_per_sec message += performance_data(perf_data, [(query_per_sec, "%s_per_sec" % query_type, warning, critical, message)]) @@ -954,13 +1024,20 @@ def check_queries_per_second(con, query_type, warning, critical, perf_data): # since it is the first run insert it query_per_sec = 0 message = "First run of check.. no data" - db.nagios_check.update({u'_id': last_count['_id']}, {'$set': {"data.%s" % query_type: {'count': num, 'ts': int(time.time())}}}) + if mongo_version == "2": + db.nagios_check.update({u'_id': last_count['_id']}, {'$set': {"data.%s" % query_type: {'count': num, 'ts': int(time.time())}}}) + else: + db.nagios_check.updateOne({u'_id': last_count['_id']}, {'$set': {"data.%s" % query_type: {'count': num, 'ts': int(time.time())}}}) + except TypeError: # # since it is the first run insert it query_per_sec = 0 message = "First run of check.. no data" - db.nagios_check.insert({'check': 'query_counts', 'data': {query_type: {'count': num, 'ts': int(time.time())}}}) + if mongo_version == "2": + db.nagios_check.insert({'check': 'query_counts', 'data': {query_type: {'count': num, 'ts': int(time.time())}}}) + else: + db.nagios_check.insert_one({'check': 'query_counts', 'data': {query_type: {'count': num, 'ts': int(time.time())}}}) return check_levels(query_per_sec, warning, critical, message) @@ -1185,15 +1262,24 @@ def check_asserts(con, host, warning, critical, perf_data): def get_stored_primary_server_name(db): """ get the stored primary server name from db. """ + + collections = '' + try: + collections = db.command('listCollections').get('cursor').get('firstBatch')[0].get('name') + except: + pass + if "last_primary_server" in db.collection_names(): stored_primary_server = db.last_primary_server.find_one()["server"] + elif "last_primary_server" in collections: + stored_primary_server = db.last_primary_server.find_one()["server"] else: stored_primary_server = None return stored_primary_server -def check_replica_primary(con, host, warning, critical, perf_data, replicaset): +def check_replica_primary(con, host, warning, critical, perf_data, replicaset, mongo_version): """ A function to check if the primary server of a replica set has changed """ if warning is None and critical is None: warning = 1 @@ -1216,7 +1302,10 @@ def check_replica_primary(con, host, warning, critical, perf_data, replicaset): saved_primary = "None" if current_primary != saved_primary: last_primary_server_record = {"server": current_primary} - db.last_primary_server.update({"_id": "last_primary"}, {"$set": last_primary_server_record}, upsert=True, safe=True) + if mongo_version == "2": + db.last_primary_server.update({"_id": "last_primary"}, {"$set": last_primary_server_record}, upsert=True, safe=True) + else: + db.last_primary_server.update({"_id": "last_primary"}, {"$set": last_primary_server_record}, upsert=True, safe=True) message = "Primary server has changed from %s to %s" % (saved_primary, current_primary) primary_status = 1 return check_levels(primary_status, warning, critical, message) diff --git a/files/check_rsnapshot.rb b/files/check_rsnapshot.rb index 885af9e..e2297e1 100644 --- a/files/check_rsnapshot.rb +++ b/files/check_rsnapshot.rb @@ -160,10 +160,14 @@ def run ##now check if backup directories exist status=0 errors=[] +snapshot_root='/rsnapshot' File.open(ARGV[0]).each do |line| - if line.match(/^backup/) + if line.match(/^snapshot_root\t/) + snapshot_root = line.split("\s")[1] + end + if line.match(/^backup\t/) #puts line.split("\s")[2] - folder='/rsnapshots/daily.0/'+line.split("\s")[2] + folder=snapshot_root+'/daily.0/'+line.split("\s")[2] if !File.directory?(folder) errors.push(folder) end @@ -179,4 +183,3 @@ def run #puts [status, stat[0]].max exit [status, stat[0]].max - diff --git a/files/check_smart.pl b/files/check_smart.pl index efb0a93..a2b223e 100644 --- a/files/check_smart.pl +++ b/files/check_smart.pl @@ -24,6 +24,9 @@ # Feb 5, 2015: Bastian de Groot - Different ATA vs. SCSI lookup (rev 5.4) # Feb 11, 2015: Josh Behrends - Allow script to run outside of nagios plugins dir / wiki url update (rev 5.5) # Feb 11, 2015: Claudio Kuenzler - Allow script to run outside of nagios plugins dir for FreeBSD too (rev 5.5) +# Mar 12, 2015: Claudio Kuenzler - Change syntax of -g parameter (regex is now awaited from input) (rev 5.6) +# Feb 6, 2017: Benedikt Heine - Fix Use of uninitialized value $device (rev 5.7) +# Mar 22, 2017: Pavel Pulec (Inuits) - allow type "auto" (rev 5.8) use strict; use Getopt::Long; @@ -31,7 +34,7 @@ use File::Basename qw(basename); my $basename = basename($0); -my $revision = '$Revision: 5.5 $'; +my $revision = '$Revision: 5.8 $'; use FindBin; use lib $FindBin::Bin; @@ -82,7 +85,7 @@ BEGIN push(@dev,$opt_d); } else { # glob all devices - try '?' first - @dev =glob($opt_g."*[a-z]"); + @dev =glob($opt_g); } foreach my $opt_dl (@dev){ @@ -103,7 +106,7 @@ BEGIN # Allow all device types currently supported by smartctl # See http://www.smartmontools.org/wiki/Supported_RAID-Controllers - if ($opt_i =~ m/(ata|scsi|3ware|areca|hpt|cciss|megaraid|sat)/) { + if ($opt_i =~ m/(ata|scsi|3ware|areca|hpt|cciss|megaraid|sat|auto)/) { $interface = $opt_i; } else { print "invalid interface $opt_i for $opt_d!\n\n"; @@ -113,7 +116,7 @@ BEGIN } -if ($device eq "") { +if (!defined($device) || $device eq "") { print "must specify a device!\n\n"; print_help(); exit $ERRORS{'UNKNOWN'}; @@ -413,11 +416,11 @@ BEGIN sub print_help { print_revision($basename,$revision); - print "\nUsage: $basename {-d=|-g=} -i=(ata|scsi|3ware,N|areca,N|hpt,L/M/N|cciss,N|megaraid,N) [-b N] [--debug]\n\n"; + print "\nUsage: $basename {-d=|-g=} -i=(auto|ata|scsi|3ware,N|areca,N|hpt,L/M/N|cciss,N|megaraid,N) [-b N] [--debug]\n\n"; print "At least one of the below. -d supersedes -g\n"; print " -d/--device: a physical block device to be SMART monitored, eg /dev/sda\n"; print " -g/--global: a regular expression name of physical devices to be SMART monitored\n"; - print " Example: /dev/sd will search for all /dev/sd* devices and report errors globally.\n"; + print " Example: '/dev/sd[a-z]' will search for all /dev/sda until /dev/sdz devices and report errors globally.\n"; print "Note that -g only works with a fixed interface input (e.g. scsi, ata), not with special interface ids like cciss,1\n"; print "\n"; print "Other options\n"; diff --git a/files/check_smart.rb b/files/check_smart.rb index 602f322..f082bcd 100644 --- a/files/check_smart.rb +++ b/files/check_smart.rb @@ -1,22 +1,139 @@ #!/usr/bin/ruby -exitStatus = 0 -msg = ['', ''] -ARGV.each { |x| - result = `perl /usr/lib64/nagios/plugins/check_smart.pl -d #{x}` - if $?.exitstatus > 0 - arr = result.split('|') - msg[0]= msg[0] + x.sub(' -i', '') + ": " + arr[0] +" " - msg[1]= msg[1] + x.sub(' -i', '')+": " + arr[1] + " " - end - if $?.exitstatus > exitStatus - exitStatus = $?.exitstatus - end -} -if exitStatus == 0 - puts "S.M.A.R.T. OK" -elsif - puts msg[0]+"|"+msg[1] +# This script is only wrapper for the original check written +# in Perl: /usr/lib64/nagios/plugins/check_smart.pl +# +# This script prepares the proper parameters for the Perl script, +# runs this script and collects a output. Then it returns proper +# valus as common NRPE check. +# +# +# This script does not require any input. It autodetects proper +# block devices and runs S.M.A.R.T. checks on them. +# + +def raid_controller() + + raid_controller = '' + + # the raid_controller detection is copied over from raid puppet module (lib/facter/raidcontroller.rb) + # + # this script supports only "megaraid" controller + if lspci = `/sbin/lspci` + lspci.split(/\n/).each do |line| + raid_controller = "sas2ircu" if line =~ /SAS2008/ + raid_controller = "megaraid" if line =~ /(MegaRAID SAS 1078|MegaSAS 9260|MegaRAID SAS 9240|MegaRAID SAS 2208|MegaRAID SAS 2008|MegaRAID SAS 2108)/ + raid_controller = "3ware" if line =~ /3ware Inc 9690SA/ + raid_controller = "aac-raid" if line =~ /Adaptec AAC-RAID/ + raid_controller = "cciss" if line =~ /Hewlett-Packard Company Smart Array G6 controllers/ + raid_controller = "areca" if line =~ /ARC-1210/ + end + else + puts 'UNKNOWN - /sbin/lspci: failed' + exit 3 + end + raid_controller +end + +def megaraid_check_params() + if File.exist?('/opt/MegaRAID/MegaCli/MegaCli64') + device_ids = `/opt/MegaRAID/MegaCli/MegaCli64 -PDList -aALL | grep -E '^Device Id: [0-9]+'` + else + puts "UNKNOWN - /opt/MegaRAID/MegaCli/MegaCli64 not found. You may want to install MegaCli" + exit 3 + end + + check_params = {} + device_ids.gsub(/^Device Id: /,'').split("\n").each_with_index do |id, index| + # it should not matter what device is used for the check, it just has to exist, hence /dev/sda + check_params.merge!({ index => { 'device' => '/dev/sda', 'interface' => "sat,auto+megaraid,#{id}"}}) + end + check_params +end + +def default_check_params() + check_params = {} + + if block_devices = `/usr/bin/facter blockdevices` + block_devices.strip.split(',').each_with_index do |dev,index| + check_params.merge!({ index => { 'device' => "/dev/#{dev}", 'interface' => 'auto'}}) + end + else + puts "UNKNOWN - I cannot get list of devices from facter. Try to run '/usr/bin/facter blockdevices'" + exit 3 + end + check_params +end + +def do_check(check_params) + warning = false + critical = false + unknown = false + output = '' + perf_data = '' + number_of_devices = 0 + + check_params.each do |index, params| + number_of_devices += 1 + device = params['device'] + interface = params['interface'] + + result = `perl /usr/lib64/nagios/plugins/check_smart.pl -d #{device} -i #{interface}` + exit_status = $?.exitstatus + + output += "#{device} - #{interface}: " + result.split('|')[0] + "; " + perf_data += "#{device} - #{interface}: " + result.split('|')[1] + "\n" + + case exit_status + when 0 + foo = 'bar' # don't do anything + when 1 + warning = true + when 2 + critical = true + else + unknown = true + end + + end + + if number_of_devices == 0 + puts 'CRITICAL - no device monitored' + exit 2 + end + + if critical + puts output + "|" + perf_data + exit 2 + end + + if warning + puts output + "|" + perf_data + exit 1 + end + + if unknown + puts output + "|" + perf_data + exit 3 + end + + puts "S.M.A.R.T. OK on #{number_of_devices} devices |" + perf_data + exit 0 +end + + + +# MAIN + +raid_controller = raid_controller() + +if raid_controller == "megaraid" + check_params = megaraid_check_params() +elsif raid_controller == '' + check_params = default_check_params() +else + puts "UNKNOWN - Raid controller '#{raid_controller} is not supported by this check" + exit 3 end -exit exitStatus +do_check(check_params) diff --git a/files/check_ssl b/files/check_ssl new file mode 100644 index 0000000..22532b1 --- /dev/null +++ b/files/check_ssl @@ -0,0 +1,21 @@ +#!/bin/bash +# +# This script checks the content of a file to match with the ssl status. +# +VHOST=$1 + +if [ -f "/tmp/checksslscan/${VHOST}_sslresult" ] +then + STATUS=$(cat /tmp/checksslscan/${VHOST}_sslresult) + if [ "$STATUS" == 'OK - score is A' ] + then + echo "OK - score is A" && exit 0 + elif [ "$STATUS" == 'WARNING - score is B' ] + then + echo "WARNING - score is B" && exit 1 + else + echo "WARNING - score is lower then B" && exit 1 + fi +else + echo "Status file not found in /tmp/checksslscan" && exit 3 +fi diff --git a/files/check_sslscan.pl b/files/check_sslscan.pl new file mode 100644 index 0000000..194006d --- /dev/null +++ b/files/check_sslscan.pl @@ -0,0 +1,179 @@ +#!/usr/bin/perl +# +# $Id: check_sslscan.pl 468 2015-04-13 08:09:53Z phil $ +# +# program: check_sslscan +# author, (c): Philippe Kueck +# +# requires: LWP::UserAgent, JSON, Getopt::Long, Pod::Usage +# + +use strict; +use warnings; + +use LWP::UserAgent; +use JSON; +use Getopt::Long; +use Pod::Usage; + +my $api = "https://api.ssllabs.com/api/v2"; +my $score = { + 'A+' => 7, 'A' => 6, 'A-' => 5, 'B' => 4, 'C' => 3, + 'D' => 2, 'E' => 1, 'F' => 0, 'T' => 0, 'M' => 0 +}; + +sub nagexit { + my $exitc = {0 => 'OK', 1 => 'WARNING', 2 => 'CRITICAL', 3 => 'UNKNOWN'}; + printf "%s - %s\n", $exitc->{$_[0]}, $_[1]; + exit $_[0] +} + +my $config = {'warn' => 'B', 'crit' => 'C'}; +Getopt::Long::Configure("no_ignore_case"); +GetOptions( + 'H=s' => \$config->{'host'}, + 'w=s' => \$config->{'warn'}, + 'c=s' => \$config->{'crit'}, + 'ip=s' => \$config->{'ip'}, + 'p' => \$config->{'publish'}, + 'x' => \$config->{'nocache'}, + 'a=i' => sub {$config->{'nocache'} = 0; $config->{'maxage'} = $_[1]}, + 'd' => \$config->{'debug'}, + 'h|help' => sub {pod2usage({'-exitval' => 3, '-verbose' => 2})} +) or pod2usage({'-exitval' => 3, '-verbose' => 0}); +pod2usage({'-exitval' => 3, '-verbose' => 0}) unless $config->{'host'}; + +my $ua = new LWP::UserAgent; +$ua->agent("nagios/check_sslscan ". ('$Revision: 468 $' =~ /(\d+)/)[0]); + +my ($resp, $result); +local $SIG{ALRM} = sub {nagexit 3, "timeout"}; +alarm 900; + +$resp = $ua->get( + sprintf "%s/analyze?host=%s&all=done&publish=%s&%s", + $api, $config->{'host'}, $config->{'publish'}?'on':'off', + $config->{'nocache'}?"startNew=on": + "fromCache=on".($config->{'maxage'}?'&maxAge='.$config->{'maxage'}:'') +); + +for (;;) { + nagexit 3, $resp->status_line unless $resp->is_success; + $result = from_json($resp->decoded_content); + last if $result->{'status'} eq 'READY'; + sleep 10; + $resp = $ua->get( + sprintf "%s/analyze?host=%s&all=done", + $api, $config->{'host'} + ) +} +alarm 0; + +if ($config->{'ip'}) { + $resp = $ua->get( + sprintf "%s/getEndpointData?host=%s&s=%s", + $api, $config->{'host'}, $config->{'ip'} + ); + $result = from_json($resp->decoded_content); + $result->{'endpoints'}[0] = $result +} + +if ($config->{'debug'}) { + use Data::Dumper; + print Dumper $result +} + +nagexit 3, "unknown result set" unless + exists $result->{'endpoints'} && + exists $result->{'endpoints'}[0] && + exists $result->{'endpoints'}[0]->{'grade'}; + +my $grade = $result->{'endpoints'}[0]->{'grade'}; + +nagexit 2, sprintf "score is %s", $grade + if $score->{$grade} <= $score->{$config->{'crit'}}; +nagexit 1, sprintf "score is %s", $grade + if $score->{$grade} <= $score->{$config->{'warn'}}; +nagexit 0, sprintf "score is %s", $grade + + +__END__ +=encoding utf8 + +=head1 NAME + +check_sslscan + +=head1 VERSION + +$Revision: 468 $ + +=head1 SYNOPSIS + + check_sslscan -H HOST -w GRADE -c GRADE [-p] [-x] [-a MAXAGE] [-ip IP address] + +=head1 OPTIONS + +=over 8 + +=item B + +Host to check using Qualys SSL Labs' sslscan. + +=item B + +IP to check when the Host has more than one endpoint + +=item B + +Warn at or below grade I (defaults to I). + +=item B + +Critical at or below I (defaults to I). + +=item B

+ +Publish results at Qualys SSL Labs. + +=item B + +do not accept cached results. + +=item B + +max cache age in hours (unsets C<-x> implicitly). + +=item B + +debug mode, print resulting json. + +=back + +=head1 DESCRIPTION + +This nagios/icinga check script checks the website's ssllabs grade. + +Possible grades: 'A+', 'A', 'A-', 'B'..'F', 'T' (trust issues), 'M' (certificate name mismatch). + +=head1 DEPENDENCIES + +=over 8 + +=item C + +=item C + +=item C + +=item C + +=back + +=head1 AUTHOR + +Philippe Kueck +credit for maxage goes to Alexander Prinz +credit for endpoint ip selection to José Miranda + +=cut \ No newline at end of file diff --git a/files/elasticsearch/check_number_of_documents.sh b/files/elasticsearch/check_number_of_documents.sh new file mode 100644 index 0000000..2985d4c --- /dev/null +++ b/files/elasticsearch/check_number_of_documents.sh @@ -0,0 +1,101 @@ +#!/bin/bash + +set -o pipefail + +PROGRAM_NAME="$1" + +[[ -z "$PROGRAM_NAME" ]] && { echo "The parameter with program name is missing"; exit 3; } +which jq &>/dev/null || { echo 'Jq is not installed'; exit 3; } + +INTERVAL=${2:-15 minutes ago} +CURRENT_EPOCH=$(date +%s%N | cut -b1-13) # ES uses epoch format in miliseconds +CURRENT_EPOCH_15MIN_LESS=$(date +%s%N -d "$INTERVAL" | cut -b1-13) +TWO_LATEST_INDEXES=$(curl -s 'localhost:9200/_stats/indexes' | jq -r '.indices | keys | .[]' | grep logstash | sort | tail -n2 | tr '\n' ',') + +[[ "$?" != 0 ]] && { echo "The request for the list of indexes failed"; exit 3; } + +number_of_events () { + + if [[ "$1" == 'get_all_events' ]];then + QUERY_PROGRAM='' + else + QUERY_PROGRAM=" + { + \"query\": { + \"match\": { + \"program\": { + \"query\": \"${1}\", + \"type\": \"phrase\" + } + } + + } + }, + { + \"query\": { + \"exists\": { + \"field\": \"json_data.data.routing_key\" + } + } + }," + fi + + NUMBER_OF_EVENTS=$(curl -s "localhost:9200/${TWO_LATEST_INDEXES}/syslog/_search?pretty" -d "{ + \"size\": 0, + \"aggs\": {}, + \"query\": { + \"filtered\": { + \"query\": { + \"query_string\": { + \"analyze_wildcard\": true, + \"query\": \"*\" + } + }, + \"filter\": { + \"bool\": { + \"must\": [ + ${QUERY_PROGRAM} + { + \"range\": { + \"@timestamp\": { + \"gte\": ${CURRENT_EPOCH_15MIN_LESS}, + \"lte\": ${CURRENT_EPOCH}, + \"format\": \"epoch_millis\" + } + } + } + ], + \"must_not\": [] + } + } + } + } + }" | + jq -r '.hits.total') + + [[ "$?" != 0 ]] && { echo "The request for the actually processed data failed"; exit 3; } + + echo $NUMBER_OF_EVENTS + +} + +NUMBER_OF_PROGRAM_EVENTS=$(number_of_events "$PROGRAM_NAME") +NUMBER_OF_ALL_EVENTS=$(number_of_events 'get_all_events') + +#echo "the number of program events: $NUMBER_OF_PROGRAM_EVENTS" +#echo "the number of all events: $NUMBER_OF_ALL_EVENTS" + +if [[ "$NUMBER_OF_ALL_EVENTS" -lt 1000 ]] +then + echo "WARNING - there is only ${NUMBER_OF_ALL_EVENTS} event(s) in ES in total during range: '${INTERVAL}'. Something wrong is probalby with ELK stack."; exit 1 +fi + +if [[ "$NUMBER_OF_PROGRAM_EVENTS" -gt 5 ]] +then + echo "OK - ${NUMBER_OF_PROGRAM_EVENTS} events were processed during range: '${INTERVAL}'"; exit 0 +elif [[ "$NUMBER_OF_PROGRAM_EVENTS" -gt 0 ]] +then + echo "WARNING - only ${NUMBER_OF_PROGRAM_EVENTS} event(s) was/were processed during range: '${INTERVAL}'"; exit 1 +else + echo "ERROR - No event was processed during range: '${INTERVAL}'"; exit 2 +fi diff --git a/files/ip_address_duplication_check.sh b/files/ip_address_duplication_check.sh new file mode 100644 index 0000000..3f31ed2 --- /dev/null +++ b/files/ip_address_duplication_check.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +# This file is managed by puppet + +# ignore localhost, and addresses with subnet /32 (because of Hetzner failover IP) +ips=$(ip addr show | grep "inet\b" | awk '{print $2}' | grep -E -v '127\.0\.0\.1|\/32' | cut -d/ -f1) +interfaces=$(ip link show | grep 'state UP' | cut -d ':' -f2 | tr -d ' ' | grep -v '\-drac') +duplications='' +arping_output='' + +arping=$(which arping) || { echo 'UNKNOWN - arping command not found'; exit 3; } + +for ip in $ips +do + for iface in $interfaces + do + arping_output="${arping_output}\n\n$($arping -D -c 1 -I "$iface" "$ip")" + [[ $? -ne 0 ]] && duplications="${duplications}${ip} " + done +done + +if [[ -z "$duplications" ]]; then + echo -e "OK - No duplicate address found.${arping_output}" + exit 0 +else + echo -e "CRITICAL - Found duplicate addresses: ${duplications}!!!${arping_output}" + exit 2 +fi diff --git a/files/zimbra_snapshot.rb b/files/zimbra_snapshot.rb deleted file mode 100644 index d24e870..0000000 --- a/files/zimbra_snapshot.rb +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/ruby - -if !File.exist?('/dev/zimbra/opt-snapshot') - puts "OK, opt-snapshot doesn't exist" - exit 0 -elsif (Time.now-File.mtime('/dev/zimbra/opt-snapshot'))/3600 < 2 - puts "OK, opt-snapshot is newer than 2h" - exit 0 -elsif (Time.now-File.mtime('/dev/zimbra/opt-snapshot'))/3600 >= 2 and (Time.now-File.mtime('/dev/zimbra/opt-snapshot'))/3600 <= 4 - puts "Warning, opt-snapshot is older than 2h" - exit 1 -elsif (Time.now-File.mtime('/dev/zimbra/opt-snapshot'))/3600 > 4 - puts "Critical, opt-snapshot is older than 4h" - exit 2 -end diff --git a/manifests/config/client.pp b/manifests/config/client.pp index 5b64189..f0fa960 100644 --- a/manifests/config/client.pp +++ b/manifests/config/client.pp @@ -4,6 +4,9 @@ # class icinga::config::client { + # Get the param in the local scope for the template + $nrpe_command_prefix = $::icinga::nrpe_command_prefix + File { owner => $::icinga::client_user, group => $::icinga::client_group, @@ -33,7 +36,7 @@ ensure => directory, } - if $::operatingsystemmajrelease == 7 { + if $::operatingsystemmajrelease == '7' { file{'/etc/systemd/system/nrpe.service': ensure => present, content => template('icinga/redhat/nrpe.service.erb'), diff --git a/manifests/config/server/common.pp b/manifests/config/server/common.pp index d3696e1..e39ea45 100644 --- a/manifests/config/server/common.pp +++ b/manifests/config/server/common.pp @@ -19,6 +19,7 @@ file{$::icinga::confdir_server: recurse => true, purge => true, + force => true, } file{"${::icinga::confdir_server}/resource.cfg": @@ -29,6 +30,7 @@ file{$::icinga::targetdir: recurse => true, purge => true, + force => true, } file{"${::icinga::targetdir}/hosts": @@ -115,6 +117,11 @@ target => "${::icinga::targetdir}/commands/check_nrpe_command.cfg", } + nagios_command{'check_nrpe_command_timeout': + command_line => "\$USER1\$/check_nrpe -u -t \$ARG1\$ -H \$HOSTADDRESS\$ -c \$ARG2\$", + target => "${::icinga::targetdir}/commands/check_nrpe_command_timeout.cfg", + } + nagios_service {'schedule_downtimes': check_command => 'schedule_script!-d0', service_description => 'Schedule Downtimes', diff --git a/manifests/params.pp b/manifests/params.pp index 4b2bfde..0d74517 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -28,6 +28,7 @@ $notification_service_opts = 'w,u,c,r' $notification_interval = '0' $max_check_attempts = '4' + $use_livestatus = true $use_ido = false $use_flapjackfeeder = false $parents = undef @@ -218,7 +219,7 @@ } default: { - fail("${module_name}: Unsupported operatingsystem ${::operatingsystem}") + fail("${module_name}: Unsupported operatingsystem ${::operatingsystem}") } } diff --git a/manifests/plugins/check_dns_sync.pp b/manifests/plugins/check_dns_sync.pp index 3195317..0a90331 100644 --- a/manifests/plugins/check_dns_sync.pp +++ b/manifests/plugins/check_dns_sync.pp @@ -3,12 +3,14 @@ # This class provides a check_dns_sync plugin. # class icinga::plugins::check_dns_sync ( + $icinga_host, $ensure = present, $contact_groups = $::environment, $max_check_attempts = $::icinga::max_check_attempts, $notification_period = 'workhours', $notifications_enabled = $::icinga::notifications_enabled, - $full_zonelist = hiera('inuits::nameserver::full_zonelist', undef), + $full_zonelist = {}, + $ignored_domains = undef, ) inherits icinga { package { 'perl-Net-DNS.x86_64': @@ -19,6 +21,10 @@ ensure => present, } + package { 'nsca-client': + ensure => present, + } + file { "${::icinga::plugindir}/check_dns_sync.pl": ensure => present, mode => '0755', @@ -28,17 +34,25 @@ notify => Service[$icinga::service_client], require => Class['icinga::config']; } - file { "${::icinga::includedir_client}/dns_sync.cfg": + file { "${::icinga::plugindir}/dns_sync.sh": ensure => 'file', - mode => '0644', + mode => '0755', owner => $::icinga::client_user, group => $::icinga::client_group, - content => template('icinga/plugins/dns_sync.cfg.erb'), - notify => Service[$::icinga::service_client], + content => template('icinga/plugins/dns_sync.sh.erb'), + } + + cron { 'dns sync check': + ensure => present, + command => "${::icinga::plugindir}/dns_sync.sh", + user => 'root', + minute => '*/10', } @@nagios_service { "check_dns_sync_${::fqdn}": - check_command => 'check_nrpe_command!check_dns_sync', + check_command => 'check_dummy!0 "All ok"', + active_checks_enabled => '0', + freshness_threshold => '600', service_description => 'dns sync', host_name => $::fqdn, contact_groups => $contact_groups, diff --git a/manifests/plugins/check_es_cluster_status.pp b/manifests/plugins/check_es_cluster_status.pp new file mode 100644 index 0000000..574fde3 --- /dev/null +++ b/manifests/plugins/check_es_cluster_status.pp @@ -0,0 +1,34 @@ +# == Class: icinga::plugins::check_es_cluster_status +class icinga::plugins::check_es_cluster_status ( + $ensure = present, + $contact_groups = $::environment, + $host = 'localhost', + $max_check_attempts = $::icinga::max_check_attempts, + $notification_period = $::icinga::notification_period, + $notifications_enabled = $::icinga::notifications_enabled, + +) inherits icinga { + file{"${::icinga::includedir_client}/check_es_cluster_status.cfg": + ensure => 'file', + mode => '0644', + owner => $::icinga::client_user, + group => $::icinga::client_group, + content => "command[check_es_cluster_status]=${::icinga::plugindir}/check_es-cluster-status.py --host=${host}", + notify => Service[$::icinga::service_client], + } + + package { 'nagios-plugins-es-cluster-status': + ensure => 'present', + } + + @@nagios_service{"check_es_cluster_status_${::fqdn}": + check_command => 'check_nrpe_command!check_es_cluster_status', + service_description => "Check ElasticSearch Cluster Status ${::fqdn}", + host_name => $::fqdn, + contact_groups => $::environment, + use => 'generic-service', + notification_period => $::icinga::notification_period, + notifications_enabled => $::icinga::notifications_enabled, + target => "${::icinga::targetdir}/services/${::fqdn}.cfg", + } +} diff --git a/manifests/plugins/check_es_jvm_usage.pp b/manifests/plugins/check_es_jvm_usage.pp new file mode 100644 index 0000000..791f64e --- /dev/null +++ b/manifests/plugins/check_es_jvm_usage.pp @@ -0,0 +1,34 @@ +# == Class: icinga::plugins::check_es_jvm_usage +class icinga::plugins::check_es_jvm_usage ( + $ensure = present, + $contact_groups = $::environment, + $host = 'localhost', + $max_check_attempts = $::icinga::max_check_attempts, + $notification_period = $::icinga::notification_period, + $notifications_enabled = $::icinga::notifications_enabled, + +) inherits icinga { + file{"${::icinga::includedir_client}/check_es_jvm_usage.cfg": + ensure => 'file', + mode => '0644', + owner => $::icinga::client_user, + group => $::icinga::client_group, + content => "command[check_es_jvm_usage]=${::icinga::plugindir}/check_es-jvm-usage.py --host=${host}", + notify => Service[$::icinga::service_client], + } + + package { 'nagios-plugins-es-jvm-usage': + ensure => 'present', + } + + @@nagios_service{"check_es_jvm_usage_${::fqdn}": + check_command => 'check_nrpe_command!check_es_jvm_usage', + service_description => "Check ElasticSearch JVM usage ${::fqdn}", + host_name => $::fqdn, + contact_groups => $::environment, + use => 'generic-service', + notification_period => $::icinga::notification_period, + notifications_enabled => $::icinga::notifications_enabled, + target => "${::icinga::targetdir}/services/${::fqdn}.cfg", + } +} diff --git a/manifests/plugins/check_es_nodes.pp b/manifests/plugins/check_es_nodes.pp new file mode 100644 index 0000000..cf9b334 --- /dev/null +++ b/manifests/plugins/check_es_nodes.pp @@ -0,0 +1,37 @@ +# == Class: icinga::plugins::check_es_nodes +class icinga::plugins::check_es_nodes ( + $ensure = present, + $expected_nodes_in_cluster = 1, + $contact_groups = $::environment, + $host = 'localhost', + $max_check_attempts = $::icinga::max_check_attempts, + $notification_period = $::icinga::notification_period, + $notifications_enabled = $::icinga::notifications_enabled, + +) inherits icinga { + file{"${::icinga::includedir_client}/check_es_nodes.cfg": + ensure => 'file', + mode => '0644', + owner => $::icinga::client_user, + group => $::icinga::client_group, + content => "command[check_es_nodes]=${::icinga::plugindir}/check_es-nodes.py --host=${host} --expected_nodes_in_cluster=${expected_nodes_in_cluster}", + notify => Service[$::icinga::service_client], + } + + package { 'nagios-plugins-es-nodes': + ensure => 'present', + } + + ## Exported config to be included in the Icinga/Nagios host + + @@nagios_service{"check_es_nodes_${::fqdn}": + check_command => 'check_nrpe_command!check_es_nodes', + service_description => "Check ElasticSearch Nodes${::fqdn}", + host_name => $::fqdn, + contact_groups => $::environment, + use => 'generic-service', + notification_period => $::icinga::notification_period, + notifications_enabled => $::icinga::notifications_enabled, + target => "${::icinga::targetdir}/services/${::fqdn}.cfg", + } +} diff --git a/manifests/plugins/check_es_unassigned_shards.pp b/manifests/plugins/check_es_unassigned_shards.pp new file mode 100644 index 0000000..5fd1c04 --- /dev/null +++ b/manifests/plugins/check_es_unassigned_shards.pp @@ -0,0 +1,34 @@ +# == Class: icinga::plugins::check_es_unassigned_shards +class icinga::plugins::check_es_unassigned_shards ( + $ensure = present, + $contact_groups = $::environment, + $host = 'localhost', + $max_check_attempts = $::icinga::max_check_attempts, + $notification_period = $::icinga::notification_period, + $notifications_enabled = $::icinga::notifications_enabled, + +) inherits icinga { + file{"${::icinga::includedir_client}/check_es_unassigned_shards.cfg": + ensure => 'file', + mode => '0644', + owner => $::icinga::client_user, + group => $::icinga::client_group, + content => "command[check_es_unassigned_shards]=${::icinga::plugindir}/check_es-unassigned-shards.py --host=${host} ", + notify => Service[$::icinga::service_client], + } + + package { 'nagios-plugins-es-unassigned-shards': + ensure => 'present', + } + + @@nagios_service{"check_es_unassigned_shards_${::fqdn}": + check_command => 'check_nrpe_command!check_es_unassigned_shards', + service_description => "Check ElasticSearch Unassigned Shards Status ${::fqdn}", + host_name => $::fqdn, + contact_groups => $::environment, + use => 'generic-service', + notification_period => $::icinga::notification_period, + notifications_enabled => $::icinga::notifications_enabled, + target => "${::icinga::targetdir}/services/${::fqdn}.cfg", + } +} diff --git a/manifests/plugins/check_https.pp b/manifests/plugins/check_https.pp new file mode 100644 index 0000000..e69de29 diff --git a/manifests/plugins/check_ip_addr_duplication.pp b/manifests/plugins/check_ip_addr_duplication.pp new file mode 100644 index 0000000..a6237e4 --- /dev/null +++ b/manifests/plugins/check_ip_addr_duplication.pp @@ -0,0 +1,47 @@ +# == Class: icinga::plugins::check_ip_addr_duplication +# +# This class provides a check_ip_addr_duplication plugin. +# +class icinga::plugins::check_ip_addr_duplication ( + $max_check_attempts = $::icinga::max_check_attempts, + $contact_groups = $::environment, + $notification_period = $::icinga::notification_period, + $notifications_enabled = $::icinga::notifications_enabled, + $additional_options = '', +) inherits icinga { + + file{"${::icinga::includedir_client}/check_ip_addr_duplication.cfg": + ensure => 'file', + mode => '0644', + owner => $::icinga::client_user, + group => $::icinga::client_group, + content => "command[check_ip_addr_duplication]=sudo ${::icinga::plugindir}/ip_address_duplication_check.sh\n", + notify => Service[$::icinga::service_client], + } + + file{"${::icinga::plugindir}/ip_address_duplication_check.sh": + ensure => present, + mode => '0755', + owner => 'root', + group => 'root', + source => 'puppet:///modules/icinga/ip_address_duplication_check.sh', + notify => Service[$icinga::service_client], + require => Class['icinga::config']; + } + + @@nagios_service { "check_ip_addr_duplication_${::fqdn}": + check_command => 'check_nrpe_command!check_ip_addr_duplication', + service_description => 'IP duplicates', + host_name => $::fqdn, + contact_groups => $contact_groups, + max_check_attempts => $max_check_attempts, + notification_period => $notification_period, + notifications_enabled => $notifications_enabled, + target => "${::icinga::targetdir}/services/${::fqdn}.cfg", + } + + sudo::conf{'configure_sudo_check_ip_addr_duplication': + content => "#managed by puppetDefaults:${::icinga::client_user} !requiretty\n +${::icinga::client_user} ALL=(ALL) NOPASSWD:${::icinga::plugindir}/ip_address_duplication_check.sh\n", + } +} diff --git a/manifests/plugins/check_pgactivity.pp b/manifests/plugins/check_pgactivity.pp new file mode 100644 index 0000000..341a052 --- /dev/null +++ b/manifests/plugins/check_pgactivity.pp @@ -0,0 +1,44 @@ +# == Class: icinga::plugins::check_pgactivity +class icinga::plugins::check_pgactivity ( + $pgsqlpassword, + $ensure = present, + $contact_groups = $::environment, + $host = 'localhost', + $max_check_attempts = $::icinga::max_check_attempts, + $notification_period = $::icinga::notification_period, + $notifications_enabled = $::icinga::notifications_enabled, +) inherits icinga { + + package {'perl-Data-Dumper': + ensure => present, + } + + package { 'nagios-plugins-pgactivity': + ensure => installed, + } + + file { "${::icinga::includedir_client}/pgactivity.cfg": + content => "command[check_pgactivity]=/usr/lib64/nagios/plugins/check_pgactivity -h ${host} -s connection", + # notify => Service[$::icinga::service_client]; + } + + file { '/var/spool/nagios/.pgpass': + ensure => file, + mode => '0600', + owner => 'nagios', + group => 'nagios', + content => "#manged by puppet\n${host}:5432:*:postgres:${pgsqlpassword}", + } + + @@nagios_service { "check_pgactivity_${::fqdn}": + check_command => 'check_nrpe_command!check_pgactivity', + service_description => 'PostgreSQL Status', + host_name => $::fqdn, + contact_groups => $contact_groups, + notification_period => $notification_period, + notifications_enabled => $notifications_enabled, + max_check_attempts => $max_check_attempts, + target => "${::icinga::targetdir}/services/${::fqdn}.cfg", + } + +} diff --git a/manifests/plugins/check_sshuttle.pp b/manifests/plugins/check_sshuttle.pp new file mode 100644 index 0000000..f2d422b --- /dev/null +++ b/manifests/plugins/check_sshuttle.pp @@ -0,0 +1,29 @@ +# == Class: icinga::plugins::check_sshuttle +# +# This class provides a check_sshuttle plugin. +# +define icinga::plugins::check_sshuttle ( + $host, + $ensure = present, + $contact_groups = $::environment, + $max_check_attempts = $::icinga::max_check_attempts, + $notification_period = $::icinga::notification_period, + $notifications_enabled = $::icinga::notifications_enabled, + $port = 22, + $subnets = [], +) { + require ::icinga + + @@nagios_service { "check_sshuttle_tunnel_${::fqdn}_${name}": + check_command => "check_tcp_other_host!${host}!${port}! -e SSH", + service_description => "sshuttle tunnel - ${name}", + host_name => $::fqdn, + contact_groups => $contact_groups, + notification_period => $notification_period, + notifications_enabled => $notifications_enabled, + max_check_attempts => $max_check_attempts, + target => "${::icinga::targetdir}/services/${::fqdn}.cfg", + } + +} + diff --git a/manifests/plugins/check_zimbra_snapshot.pp b/manifests/plugins/check_zimbra_snapshot.pp deleted file mode 100644 index d1f8421..0000000 --- a/manifests/plugins/check_zimbra_snapshot.pp +++ /dev/null @@ -1,47 +0,0 @@ -# == Class: icinga::plugins::check_zimbra_snapshot -# -# This class provides a check_zimbra_snapshot plugin. -# -class icinga::plugins::check_zimbra_snapshot ( - $ensure = present, - $contact_groups = $::environment, - $max_check_attempts = $::icinga::max_check_attempts, - $notification_period = $::icinga::notification_period, - $notifications_enabled = $::icinga::notifications_enabled, - -) inherits icinga { - - - file { "${::icinga::plugindir}/zimbra_snapshot.rb": - ensure => present, - mode => '0755', - owner => 'root', - group => 'root', - source => 'puppet:///modules/icinga/zimbra_snapshot.rb', - notify => Service[$icinga::service_client], - require => Class['icinga::config']; - } - file { "${::icinga::includedir_client}/zimbra_snapshot.cfg": - ensure => 'file', - mode => '0644', - owner => $::icinga::client_user, - group => $::icinga::client_group, - content => template('icinga/plugins/zimbra_snapshot.cfg.erb'), - notify => Service[$::icinga::service_client], - } - - - - @@nagios_service { "check_zimbra_snapshot_${::fqdn}": - check_command => 'check_nrpe_command!check_zimbra_snapshot', - service_description => 'zimbra snapshot', - host_name => $::fqdn, - contact_groups => $contact_groups, - notification_period => $notification_period, - notifications_enabled => $notifications_enabled, - max_check_attempts => $max_check_attempts, - target => "${::icinga::targetdir}/services/${::fqdn}.cfg", - } - - } - diff --git a/manifests/plugins/checkalldisks.pp b/manifests/plugins/checkalldisks.pp index 6fb42d0..f198707 100644 --- a/manifests/plugins/checkalldisks.pp +++ b/manifests/plugins/checkalldisks.pp @@ -9,7 +9,7 @@ $contact_groups = $::environment, $notification_period = $::icinga::notification_period, $notifications_enabled = $::icinga::notifications_enabled, - $additional_options = '', + $additional_options = '', ) inherits icinga { if $icinga::client { @@ -18,7 +18,7 @@ mode => '0644', owner => $::icinga::client_user, group => $::icinga::client_group, - content => "command[check_all_disks]=sudo ${::icinga::plugindir}/check_disk -w ${check_warning} -c ${check_critical} -W ${check_warning} -C ${additional_options}\n", + content => "command[check_all_disks]=sudo ${::icinga::plugindir}/check_disk -w ${check_warning} -c ${check_critical} -W ${check_warning} ${additional_options}\n", notify => Service[$::icinga::service_client], } @@ -34,4 +34,7 @@ } } + sudo::conf{'configure_sudo_checkalldisks': + content => "Defaults:${::icinga::client_user} !requiretty\n${::icinga::client_user} ALL=(ALL) NOPASSWD:${::icinga::plugindir}/check_disk\n", + } } diff --git a/manifests/plugins/checkbacula.pp b/manifests/plugins/checkbacula.pp deleted file mode 100644 index 454c98b..0000000 --- a/manifests/plugins/checkbacula.pp +++ /dev/null @@ -1,45 +0,0 @@ -# == Class: icinga::plugins::checkbacula -# -# This class provides a checkbacula plugin. -# -define icinga::plugins::checkbacula ( - $pkgname = 'nagios-plugins-bacula', - $jobname = $::fqdn, - $warning = '1', - $critical = '0', - $contact_groups = $::environment, - $notification_period = 'workhours', - $notifications_enabled = $::icinga::notifications_enabled, -) { - - require ::icinga - - if $icinga::client { - if ! defined(Package[$pkgname]) { - package{$pkgname: - ensure => '0.0.5-2' - } - } - - file{"${::icinga::includedir_client}/bacula_${jobname}.cfg": - ensure => 'file', - mode => '0644', - owner => $::icinga::client_user, - group => $::icinga::client_group, - content => "command[check_bacula_${jobname}]=${::icinga::plugindir}/check_bacula -j ${jobname} -w ${warning} -c ${critical}\n", - notify => Service[$::icinga::service_client], - } - - @@nagios_service{"check_bacula_${jobname}": - check_command => "check_nrpe_command!check_bacula_${jobname}", - service_description => "Bacula Job: ${jobname}", - host_name => $::fqdn, - use => 'generic-service', - contact_groups => $contact_groups, - notification_period => $notification_period, - notifications_enabled => $notifications_enabled, - target => "${::icinga::targetdir}/services/${::fqdn}.cfg", - } - } - -} diff --git a/manifests/plugins/checkcarbon.pp b/manifests/plugins/checkcarbon.pp index ca8be48..ac93914 100644 --- a/manifests/plugins/checkcarbon.pp +++ b/manifests/plugins/checkcarbon.pp @@ -10,36 +10,35 @@ $notifications_enabled = $::icinga::notifications_enabled, ) inherits icinga { - file { "${::icinga::plugindir}/check_process": - ensure => present, - mode => '0755', - owner => 'root', - group => 'root', - source => 'puppet:///modules/icinga/check_process', - notify => Service[$icinga::service_client], - require => Class['icinga::config']; - } - file { "${::icinga::includedir_client}/carbon.cfg": - ensure => 'file', - mode => '0644', - owner => $::icinga::client_user, - group => $::icinga::client_group, - content => template('icinga/plugins/carbon.cfg.erb'), - notify => Service[$::icinga::service_client], - } - - + file { "${::icinga::plugindir}/check_process": + ensure => present, + mode => '0755', + owner => 'root', + group => 'root', + source => 'puppet:///modules/icinga/check_process', + notify => Service[$icinga::service_client], + require => Class['icinga::config']; + } - @@nagios_service { "check_carbon_cache_${::fqdn}": - check_command => 'check_nrpe_command!check_carbon', - service_description => 'Carbon cache', - host_name => $::fqdn, - contact_groups => $contact_groups, - notification_period => $notification_period, - notifications_enabled => $notifications_enabled, - max_check_attempts => $max_check_attempts, - target => "${::icinga::targetdir}/services/${::fqdn}.cfg", - } + file { "${::icinga::includedir_client}/carbon.cfg": + ensure => 'file', + mode => '0644', + owner => $::icinga::client_user, + group => $::icinga::client_group, + content => template('icinga/plugins/carbon.cfg.erb'), + notify => Service[$::icinga::service_client], + } + @@nagios_service { "check_carbon_cache_${::fqdn}": + check_command => 'check_nrpe_command!check_carbon', + service_description => 'Carbon cache', + host_name => $::fqdn, + contact_groups => $contact_groups, + notification_period => $notification_period, + notifications_enabled => $notifications_enabled, + max_check_attempts => $max_check_attempts, + target => "${::icinga::targetdir}/services/${::fqdn}.cfg", } +} + diff --git a/manifests/plugins/checkcertexpiry.pp b/manifests/plugins/checkcertexpiry.pp new file mode 100644 index 0000000..2dc44bd --- /dev/null +++ b/manifests/plugins/checkcertexpiry.pp @@ -0,0 +1,52 @@ +# == Class: icinga::plugins::checkcertexpiry +# +# This defined type provides a checkcertexpiry plugin. +# +define icinga::plugins::checkcertexpiry ( + $max_check_attempts = $::icinga::max_check_attempts, + $contact_groups = $::environment, + $notification_period = $::icinga::notification_period, + $notifications_enabled = $::icinga::notifications_enabled, + $warning_days = 14, + $critical_days = 4, +) { + require ::icinga + + if ! defined(Package['nagios-plugins-ssl-cert']) { + package{ 'nagios-plugins-ssl-cert': + ensure => present, + } + } + + if ! defined(Sudo::Conf['ssl_cert_expity']) { + sudo::conf{'ssl_cert_expity': + content => "Defaults:nagios !requiretty + nagios ALL=(ALL) NOPASSWD:/usr/lib64/nagios/plugins/check_ssl-cert\n", + } + } + + $cert = inline_template("<%= @name.gsub(/\/.*\//,'') %>") + file{"${::icinga::includedir_client}/check_cert_expiry_${cert}.cfg": + ensure => 'file', + mode => '0644', + owner => $::icinga::client_user, + group => $::icinga::client_group, + content => template('icinga/plugins/check_cert_expiry.cfg.erb'), + notify => Service[$::icinga::service_client], + } + + @@nagios_service { "check_cert_expiry_${::fqdn}_${cert}": + check_command => "check_nrpe_command!check_local_cert_expiry_${cert}", + service_description => "Check Cert Expiry - ${cert}", + host_name => $::fqdn, + contact_groups => $contact_groups, + max_check_attempts => $max_check_attempts, + notification_period => $notification_period, + notifications_enabled => $notifications_enabled, + target => "${::icinga::targetdir}/services/${::fqdn}.cfg", + } + + } + + + diff --git a/manifests/plugins/checkcollectiveaccess.pp b/manifests/plugins/checkcollectiveaccess.pp new file mode 100644 index 0000000..f776172 --- /dev/null +++ b/manifests/plugins/checkcollectiveaccess.pp @@ -0,0 +1,43 @@ +# == Class: icinga::plugins::checkcollectiveaccess +class icinga::plugins::checkcollectiveaccess ( + $host, + $user, + $password, + $configuration, + $contact_groups = $::environment, + $max_check_attempts = $::icinga::max_check_attempts, + $notification_period = $::icinga::notification_period, + $notifications_enabled = $::icinga::notifications_enabled, +) inherits ::icinga { + + + + file{"${::icinga::includedir_client}/collectiveaccess.cfg": + ensure => 'file', + mode => '0644', + owner => $::icinga::client_user, + group => $::icinga::client_group, + content => "command[check_collectiveaccess]=${::icinga::usrlib}/nagios/plugins/check_collective-access.rb -h ${host} -u ${user} -p ${password} -c ${::icinga::includedir_client}/ca_config.yaml\n", + notify => Service[$::icinga::service_client], + } + + file {"${::icinga::includedir_client}/ca_config.yaml": + content => inline_template('<%= @configuration.to_yaml %>'), + mode => '0644', + owner => $::icinga::client_user, + group => $::icinga::client_group, + notify => Service[$::icinga::service_client], + } + + @@nagios_service{"check_collectiveaccess_${::fqdn}": + check_command => 'check_nrpe_command!check_collectiveaccess', + service_description => 'CollectiveAccess', + host_name => $::fqdn, + contact_groups => $contact_groups, + max_check_attempts => $max_check_attempts, + notification_period => $notification_period, + notifications_enabled => $notifications_enabled, + target => "${::icinga::targetdir}/services/${::fqdn}.cfg", + } + +} diff --git a/manifests/plugins/checkcrm.pp b/manifests/plugins/checkcrm.pp index c58a6f6..c1134fa 100644 --- a/manifests/plugins/checkcrm.pp +++ b/manifests/plugins/checkcrm.pp @@ -15,10 +15,18 @@ require icinga + # we used this package in the past on Centos boxes + # but it was replaced with nagios-plugins-crm. The + # check is the same but the naming convention is + # correct + package { 'nagios-plugins-checkcrm': + ensure => absent, + } + if $icinga::client { $pkg_nagios_plugin_checkcrm = $::operatingsystem ? { - /CentOS|RedHat/ => 'nagios-plugins-checkcrm', + /CentOS|RedHat/ => 'nagios-plugins-crm', default => fail('Operating system not supported'), } @@ -28,12 +36,11 @@ } package { $pkg_nagios_plugin_checkcrm: - ensure => installed, + ensure => installed, + require => Package['nagios-plugins-checkcrm'], } - package { $pkg_perl_nagios_plugin: - ensure => installed, - } + ensure_resource ('package', $pkg_perl_nagios_plugin, { 'ensure' => 'installed' }) file{"${::icinga::includedir_client}/check_crm_${host_name}.cfg": @@ -41,10 +48,14 @@ mode => '0644', owner => $::icinga::client_user, group => $::icinga::client_group, - content => "command[check_crm_${host_name}]=${::icinga::plugindir}/check_crm\n", + content => "command[check_crm_${host_name}]=sudo ${::icinga::plugindir}/check_crm -c\n", notify => Service[$::icinga::service_client], } + sudo::conf{'nrpe_crm_mon': + content => "Defaults:nagios !requiretty\nnagios ALL=(ALL) NOPASSWD:${::icinga::plugindir}/check_crm\n", + } + @@nagios_service{"check_crm_${host_name}": check_command => "check_nrpe_command!check_crm_${host_name}", service_description => 'Pacemaker', @@ -56,4 +67,4 @@ target => "${::icinga::targetdir}/services/${host_name}.cfg", } } -} \ No newline at end of file +} diff --git a/manifests/plugins/checkcronlogs.pp b/manifests/plugins/checkcronlogs.pp new file mode 100644 index 0000000..9be5965 --- /dev/null +++ b/manifests/plugins/checkcronlogs.pp @@ -0,0 +1,52 @@ +# == Class: icinga::plugins::checkcronlogs +# +# This defined type provides a checkcronlogs plugin. +# +class icinga::plugins::checkcronlogs ( + $max_check_attempts = $::icinga::max_check_attempts, + $contact_groups = $::environment, + $notification_period = $::icinga::notification_period, + $notifications_enabled = $::icinga::notifications_enabled, + $ignored_jobs = hiera(ignored_jobs, undef), + +) inherits icinga { + + + file { "${::icinga::plugindir}/check_cron_logs.sh": + ensure => present, + mode => '0755', + owner => 'root', + group => 'root', + source => 'puppet:///modules/icinga/check_cron_logs.sh', + notify => Service[$icinga::service_client], + require => Class['icinga::config']; + } + file{"${::icinga::includedir_client}/check_cron_logs.cfg": + ensure => 'file', + mode => '0644', + owner => $::icinga::client_user, + group => $::icinga::client_group, + content => template('icinga/plugins/cron_logs.cfg.erb'), + notify => Service[$::icinga::service_client], + } + + + + @@nagios_service { "check_cron_logs_${::fqdn}": + check_command => 'check_nrpe_command!check_cron_logs', + check_interval => '60', + service_description => 'Check cron logs', + host_name => $::fqdn, + contact_groups => $contact_groups, + max_check_attempts => $max_check_attempts, + notification_period => $notification_period, + notifications_enabled => $notifications_enabled, + target => "${::icinga::targetdir}/services/${::fqdn}.cfg", + } + sudo::conf{'cron_logs_check_conf': + content => "Defaults:nagios !requiretty + nagios ALL=(ALL) NOPASSWD:${::icinga::plugindir}/check_cron_logs.sh\n", + } + + } + diff --git a/manifests/plugins/checkdrupalcron.pp b/manifests/plugins/checkdrupalcron.pp index 82294ca..d669668 100644 --- a/manifests/plugins/checkdrupalcron.pp +++ b/manifests/plugins/checkdrupalcron.pp @@ -5,13 +5,14 @@ # Warning and Critical expressed in seconds. 3600sec = 1h, 7200sec = 2h define icinga::plugins::checkdrupalcron ( $pkgname = $::operatingsystem ? { - 'centos' => 'nagios-plugins-drupalcron', - 'debian' => 'nagios-plugin-drupalcron', + 'centos' => 'nagios-plugins-drupal-cron', + 'debian' => 'nagios-plugins-drupal-cron', }, $notification_period = $::icinga::notification_period, $notifications_enabled = $::icinga::notifications_enabled, $host_name = $::fqdn, $contact_groups = $::environment, + $use_sudo = true, $warning = '3600', $critical = '7200', $uri = '', @@ -28,12 +29,19 @@ } } + if $use_sudo { + $content="command[check_drupal_cron_${title}]=sudo ${::icinga::plugindir}/check_drupal-cron -u ${uri} -r ${root} -w ${warning} -c ${critical}\n" + } + else { + $content="command[check_drupal_cron_${title}]=${::icinga::plugindir}/check_drupal-cron -u ${uri} -r ${root} -w ${warning} -c ${critical}\n" + } + file{"${::icinga::includedir_client}/check_drupal_cron_${title}.cfg": ensure => 'file', mode => '0644', owner => $::icinga::client_user, group => $::icinga::client_group, - content => "command[check_drupal_cron_${title}]=sudo ${::icinga::plugindir}/check_drupal_cron -u ${uri} -r ${root} -w ${warning} -c ${critical}\n", + content => $content, notify => Service[$::icinga::service_client], } diff --git a/manifests/plugins/checkelasticsearch.pp b/manifests/plugins/checkelasticsearch.pp index ea7338f..c96a014 100644 --- a/manifests/plugins/checkelasticsearch.pp +++ b/manifests/plugins/checkelasticsearch.pp @@ -3,21 +3,20 @@ # This class provides a checkelasticsearch plugin. # class icinga::plugins::checkelasticsearch ( - $pkgname = 'nagios-plugin-elasticsearch', + $pkgname = 'nagios-plugins-elasticsearch', ) { + if $icinga::client { - if !defined(Package['python-pip']){ - package{'python-pip': + if !defined(Package[$pkgname]) { + package {$pkgname: ensure => present, } } - if !defined(Package[$pkgname]) { - package{$pkgname: - ensure => present, - provider => 'pip', - require => Package['python-pip'], + if !defined(Package['python-nagioscheck']) { + package {'python-nagioscheck': + ensure => present, } } @@ -26,7 +25,7 @@ mode => '0644', owner => $::icinga::client_user, group => $::icinga::client_group, - content => 'command[check_elasticsearch]=/usr/bin/check_elasticsearch', + content => "command[check_elasticsearch]=${::icinga::plugindir}/check_elasticsearch.py", notify => Service[$::icinga::service_client], } diff --git a/manifests/plugins/checkfileage.pp b/manifests/plugins/checkfileage.pp new file mode 100644 index 0000000..ad02dd7 --- /dev/null +++ b/manifests/plugins/checkfileage.pp @@ -0,0 +1,36 @@ +# == Class: icinga::plugins::checkfileage +define icinga::plugins::checkfileage ( + $critical, + $warning, + $file, + $datetype = 'M', + $not_found_exit_code = 3, + $contact_groups = $::environment, + $max_check_attempts = $::icinga::max_check_attempts, + $notification_period = $::icinga::notification_period, + $notifications_enabled = $::icinga::notifications_enabled, +) { + + require ::icinga + $_file = inline_template("<%= @file.gsub('/','_') %>") + file{"${::icinga::includedir_client}/check_file_age${_file}.cfg": + ensure => 'file', + mode => '0644', + owner => $::icinga::client_user, + group => $::icinga::client_group, + content => "command[check_file_age${_file}]=${::icinga::usrlib}/nagios/plugins/check_fileage.py -w ${warning} -c ${critical} -f ${file} -d ${datetype} -n ${not_found_exit_code}", + notify => Service[$::icinga::service_client], + } + + @@nagios_service{"check_fileage${_file}_${::fqdn}": + check_command => "check_nrpe_command!check_file_age${_file}", + service_description => "Check File Age ${file}", + host_name => $::fqdn, + contact_groups => $contact_groups, + max_check_attempts => $max_check_attempts, + notification_period => $notification_period, + notifications_enabled => $notifications_enabled, + target => "${::icinga::targetdir}/services/${::fqdn}.cfg", + } + +} diff --git a/manifests/plugins/checkgluster.pp b/manifests/plugins/checkgluster.pp index c4263b2..2b72653 100644 --- a/manifests/plugins/checkgluster.pp +++ b/manifests/plugins/checkgluster.pp @@ -10,41 +10,41 @@ $notifications_enabled = $::icinga::notifications_enabled, ) inherits icinga { - file { "${::icinga::plugindir}/check_gluster.sh": - ensure => present, - mode => '0755', - owner => 'root', - group => 'root', - source => 'puppet:///modules/icinga/check_gluster.sh', - notify => Service[$icinga::service_client], - require => Class['icinga::config']; - } - file { "${::icinga::includedir_client}/check_gluster.cfg": - ensure => 'file', - mode => '0644', - owner => $::icinga::client_user, - group => $::icinga::client_group, - content => template('icinga/plugins/gluster.cfg.erb'), - notify => Service[$::icinga::service_client], - } - + file { "${::icinga::plugindir}/check_gluster.sh": + ensure => present, + mode => '0755', + owner => 'root', + group => 'root', + source => 'puppet:///modules/icinga/check_gluster.sh', + notify => Service[$icinga::service_client], + require => Class['icinga::config']; + } + file { "${::icinga::includedir_client}/check_gluster.cfg": + ensure => 'file', + mode => '0644', + owner => $::icinga::client_user, + group => $::icinga::client_group, + content => template('icinga/plugins/gluster.cfg.erb'), + notify => Service[$::icinga::service_client], + } - @@nagios_service { "check_gluster_${::fqdn}": - check_command => 'check_nrpe_command!check_gluster', - service_description => 'check gluster', - host_name => $::fqdn, - contact_groups => $contact_groups, - notification_period => $notification_period, - notifications_enabled => $notifications_enabled, - max_check_attempts => $max_check_attempts, - target => "${::icinga::targetdir}/services/${::fqdn}.cfg", - } - sudo::conf{'gluster_check_conf': - content => "Defaults:nagios !requiretty - nagios ALL=(ALL) NOPASSWD:/usr/sbin/gluster *\n", - } + @@nagios_service { "check_gluster_${::fqdn}": + check_command => 'check_nrpe_command!check_gluster', + service_description => 'check gluster', + host_name => $::fqdn, + contact_groups => $contact_groups, + notification_period => $notification_period, + notifications_enabled => $notifications_enabled, + max_check_attempts => $max_check_attempts, + target => "${::icinga::targetdir}/services/${::fqdn}.cfg", + } + sudo::conf{'gluster_check_conf': + content => "Defaults:nagios !requiretty + nagios ALL=(ALL) NOPASSWD:/usr/sbin/gluster *\n", } +} + diff --git a/manifests/plugins/checkgraphite.pp b/manifests/plugins/checkgraphite.pp index 87abb8e..a49e26e 100644 --- a/manifests/plugins/checkgraphite.pp +++ b/manifests/plugins/checkgraphite.pp @@ -15,8 +15,10 @@ } } - @@nagios_command{'check_graphite': + nagios_command{'check_graphite': ensure => present, + owner => $::icinga::server_user, + group => $::icinga::server_group, command_line => '$USER1$/check_graphite -u \'$ARG1$\' -w $ARG2$ -c $ARG3$', target => "${::icinga::targetdir}/commands/check_graphite.cfg", } diff --git a/manifests/plugins/checkhaproxy.pp b/manifests/plugins/checkhaproxy.pp index d6fea1f..75eece1 100644 --- a/manifests/plugins/checkhaproxy.pp +++ b/manifests/plugins/checkhaproxy.pp @@ -1,49 +1,34 @@ # == Class: icinga::plugins::checkhaproxy # -# This class provides a checkhaproxy plugin. +# This class only creates proper NRPE config with command 'check_haproxy' but +# the exported resource is defined in icinga::plugins::checkhaproxy::nagios_service +# # class icinga::plugins::checkhaproxy ( - $ensure = present, - $contact_groups = $::environment, - $max_check_attempts = $::icinga::max_check_attempts, - $notification_period = $::icinga::notification_period, - $notifications_enabled = $::icinga::notifications_enabled, - $username = hiera('haproxy_username', 'haproxy'), - $password = hiera('haproxy_pass', 'V3ry_Str0ng_P4ssword'), - + $contact_groups = $::environment, + $max_check_attempts = $::icinga::max_check_attempts, + $notification_period = $::icinga::notification_period, + $notifications_enabled = $::icinga::notifications_enabled, + $target = "${::icinga::targetdir}/services/${::fqdn}.cfg", ) inherits icinga { + file { "${::icinga::plugindir}/check_haproxy.rb": + ensure => present, + mode => '0755', + owner => 'root', + group => 'root', + source => 'puppet:///modules/icinga/check_haproxy.rb', + notify => Service[$icinga::service_client], + require => Class['icinga::config']; + } - file { "${::icinga::plugindir}/check_haproxy.rb": - ensure => present, - mode => '0755', - owner => 'root', - group => 'root', - source => 'puppet:///modules/icinga/check_haproxy.rb', - notify => Service[$icinga::service_client], - require => Class['icinga::config']; - } - file { "${::icinga::includedir_client}/haproxy.cfg": - ensure => 'file', - mode => '0644', - owner => $::icinga::client_user, - group => $::icinga::client_group, - content => template('icinga/plugins/haproxy.cfg.erb'), - notify => Service[$::icinga::service_client], - } - - - - @@nagios_service { "check_haproxy_${::fqdn}": - check_command => 'check_nrpe_command!check_haproxy', - service_description => 'HAproxy backends', - host_name => $::fqdn, - contact_groups => $contact_groups, - notification_period => $notification_period, - notifications_enabled => $notifications_enabled, - max_check_attempts => $max_check_attempts, - target => "${::icinga::targetdir}/services/${::fqdn}.cfg", - } - + file { "${::icinga::includedir_client}/haproxy.cfg": + ensure => 'file', + mode => '0644', + owner => $::icinga::client_user, + group => $::icinga::client_group, + content => template('icinga/plugins/haproxy.cfg.erb'), + notify => Service[$::icinga::service_client], } +} diff --git a/manifests/plugins/checkhaproxy/nagios_service.pp b/manifests/plugins/checkhaproxy/nagios_service.pp new file mode 100644 index 0000000..c545d32 --- /dev/null +++ b/manifests/plugins/checkhaproxy/nagios_service.pp @@ -0,0 +1,25 @@ +# == Define: icinga::plugins::checkhaproxy +# +# This define exports all IP addresses we want +# to check. +# +define icinga::plugins::checkhaproxy::nagios_service ( + $url_to_check = $title, +) { + + include ::icinga::plugins::checkhaproxy + + $ip_address_from_string = inline_template("<%= @url_to_check.gsub(/.*?([1-9][0-9.]*[0-9]).*/, '\\1') %>") + + @@nagios_service { "check_haproxy_${::fqdn}_${url_to_check}": + check_command => "check_nrpe_command_args!check_haproxy!'${url_to_check}'", + service_description => "HAProxy check on ${ip_address_from_string}", + host_name => $::fqdn, + contact_groups => $::icinga::plugins::checkhaproxy::contact_groups, + notification_period => $::icinga::plugins::checkhaproxy::notification_period, + notifications_enabled => $::icinga::plugins::checkhaproxy::notifications_enabled, + max_check_attempts => $::icinga::plugins::checkhaproxy::max_check_attempts, + target => $::icinga::plugins::checkhaproxy::target, + } + +} diff --git a/manifests/plugins/checkhttps.pp b/manifests/plugins/checkhttps.pp new file mode 100644 index 0000000..4967ddf --- /dev/null +++ b/manifests/plugins/checkhttps.pp @@ -0,0 +1,29 @@ +# == Class: icinga::plugins::checkhttps +# +# This class provides a checkhttps plugin. +# +define icinga::plugins::checkhttps ( + $vhost = $name, + $port = 443, + $expected_codes = '200,301,302', + $contact_groups = $::environment, + $max_check_attempts = $::icinga::max_check_attempts, + $notification_period = $::icinga::notification_period, + $notifications_enabled = $::icinga::notifications_enabled, +) { + + require ::icinga + if $icinga::client { + @@nagios_service { "check_https_${::fqdn}_${vhost}": + check_command => "check_http!-H ${vhost} -S -p ${port} -e ${expected_codes} --sni", + service_description => "check https ${vhost}", + host_name => $::fqdn, + contact_groups => $contact_groups, + max_check_attempts => $max_check_attempts, + notification_period => $notification_period, + notifications_enabled => $notifications_enabled, + target => "${::icinga::targetdir}/services/${::fqdn}.cfg", + } + } + +} diff --git a/manifests/plugins/checkhttps_certificate.pp b/manifests/plugins/checkhttps_certificate.pp new file mode 100644 index 0000000..40af75c --- /dev/null +++ b/manifests/plugins/checkhttps_certificate.pp @@ -0,0 +1,30 @@ +# == Class: icinga::plugins::checkhttps_certificate +# +# This class provides a checkhttps_certificate plugin. +# +define icinga::plugins::checkhttps_certificate ( + $vhost = $name, + $port = 443, + $expected_codes = '200,301,302', + $cert_validity_days_required = 14, + $contact_groups = $::environment, + $max_check_attempts = $::icinga::max_check_attempts, + $notification_period = $::icinga::notification_period, + $notifications_enabled = $::icinga::notifications_enabled, +) { + + require ::icinga + if $icinga::client { + @@nagios_service { "check_https_certificate_${::fqdn}_${vhost}": + check_command => "check_http!-H ${vhost} -S -p ${port} -e ${expected_codes} --sni -C ${cert_validity_days_required}", + service_description => "check https certificate ${vhost}", + host_name => $::fqdn, + contact_groups => $contact_groups, + max_check_attempts => $max_check_attempts, + notification_period => $notification_period, + notifications_enabled => $notifications_enabled, + target => "${::icinga::targetdir}/services/${::fqdn}.cfg", + } + } + +} diff --git a/manifests/plugins/checkipmi.pp b/manifests/plugins/checkipmi.pp index 3a591c5..b07200c 100644 --- a/manifests/plugins/checkipmi.pp +++ b/manifests/plugins/checkipmi.pp @@ -11,49 +11,48 @@ $ignored_sensors = hiera('ignored_sensors', undef), ) inherits icinga { - package { 'perl-IPC-Run.noarch': - ensure => present, - } - - package { 'freeipmi': - ensure => present, - } - - file { "${::icinga::plugindir}/check_ipmi_sensor": - ensure => present, - mode => '0755', - owner => 'root', - group => 'root', - source => 'puppet:///modules/icinga/check_ipmi_sensor', - notify => Service[$icinga::service_client], - require => Class['icinga::config']; - } - file { "${::icinga::includedir_client}/ipmi.cfg": - ensure => 'file', - mode => '0644', - owner => $::icinga::client_user, - group => $::icinga::client_group, - content => template('icinga/plugins/ipmi.cfg.erb'), - notify => Service[$::icinga::service_client], - } - - - - @@nagios_service { "check_ipmi_${::fqdn}": - check_command => 'check_nrpe_command!check_ipmi', - service_description => 'IPMI', - host_name => $::fqdn, - contact_groups => $contact_groups, - notification_period => $notification_period, - notifications_enabled => $notifications_enabled, - max_check_attempts => $max_check_attempts, - target => "${::icinga::targetdir}/services/${::fqdn}.cfg", - } - - sudo::conf{'ipmi_check_conf': + package { 'perl-IPC-Run.noarch': + ensure => present, + } + + package { 'freeipmi': + ensure => present, + } + + file { "${::icinga::plugindir}/check_ipmi_sensor": + ensure => present, + mode => '0755', + owner => 'root', + group => 'root', + source => 'puppet:///modules/icinga/check_ipmi_sensor', + notify => Service[$icinga::service_client], + require => Class['icinga::config']; + } + file { "${::icinga::includedir_client}/ipmi.cfg": + ensure => 'file', + mode => '0644', + owner => $::icinga::client_user, + group => $::icinga::client_group, + content => template('icinga/plugins/ipmi.cfg.erb'), + notify => Service[$::icinga::service_client], + } + + + @@nagios_service { "check_ipmi_${::fqdn}": + check_command => 'check_nrpe_command!check_ipmi', + service_description => 'IPMI', + host_name => $::fqdn, + contact_groups => $contact_groups, + notification_period => $notification_period, + notifications_enabled => $notifications_enabled, + max_check_attempts => $max_check_attempts, + target => "${::icinga::targetdir}/services/${::fqdn}.cfg", + } + + sudo::conf{'ipmi_check_conf': content => "Defaults:nagios !requiretty nagios ALL=(ALL) NOPASSWD:/usr/sbin/ipmimonitoring,/usr/sbin/ipmi-sensors\n", - } - } +} + diff --git a/manifests/plugins/checkipmichassis.pp b/manifests/plugins/checkipmichassis.pp index 4a10981..18b3e1c 100644 --- a/manifests/plugins/checkipmichassis.pp +++ b/manifests/plugins/checkipmichassis.pp @@ -10,45 +10,43 @@ $notifications_enabled = $::icinga::notifications_enabled, ) inherits icinga { - package { 'perl-Nagios-Plugin': + package { 'perl-Nagios-Plugin': ensure => 'installed' - } - - file { "${::icinga::plugindir}/check_ipmitool.pl": - ensure => present, - mode => '0755', - owner => 'root', - group => 'root', - source => 'puppet:///modules/icinga/check_ipmitool.pl', - notify => Service[$icinga::service_client], - require => Class['icinga::config']; - } - file { "${::icinga::includedir_client}/ipmi_chassis.cfg": - ensure => 'file', - mode => '0644', - owner => $::icinga::client_user, - group => $::icinga::client_group, - content => template('icinga/plugins/ipmi_chassis.cfg.erb'), - notify => Service[$::icinga::service_client], - } - + } + file { "${::icinga::plugindir}/check_ipmitool.pl": + ensure => present, + mode => '0755', + owner => 'root', + group => 'root', + source => 'puppet:///modules/icinga/check_ipmitool.pl', + notify => Service[$icinga::service_client], + require => Class['icinga::config']; + } + file { "${::icinga::includedir_client}/ipmi_chassis.cfg": + ensure => 'file', + mode => '0644', + owner => $::icinga::client_user, + group => $::icinga::client_group, + content => template('icinga/plugins/ipmi_chassis.cfg.erb'), + notify => Service[$::icinga::service_client], + } - @@nagios_service { "ipmi_chassis_status${::fqdn}": - check_command => 'check_nrpe_command!check_ipmi_chassis', - service_description => 'IPMI chassis status', - host_name => $::fqdn, - contact_groups => $contact_groups, - notification_period => $notification_period, - notifications_enabled => $notifications_enabled, - max_check_attempts => $max_check_attempts, - target => "${::icinga::targetdir}/services/${::fqdn}.cfg", - } + @@nagios_service { "ipmi_chassis_status${::fqdn}": + check_command => 'check_nrpe_command!check_ipmi_chassis', + service_description => 'IPMI chassis status', + host_name => $::fqdn, + contact_groups => $contact_groups, + notification_period => $notification_period, + notifications_enabled => $notifications_enabled, + max_check_attempts => $max_check_attempts, + target => "${::icinga::targetdir}/services/${::fqdn}.cfg", + } - sudo::conf{'ipmi_chassis_conf': + sudo::conf{'ipmi_chassis_conf': content => "Defaults:nagios !requiretty nagios ALL=(ALL) NOPASSWD:/usr/bin/ipmitool\n", - } - } +} + diff --git a/manifests/plugins/checkload.pp b/manifests/plugins/checkload.pp index 2750851..02c1a4e 100644 --- a/manifests/plugins/checkload.pp +++ b/manifests/plugins/checkload.pp @@ -4,8 +4,8 @@ # class icinga::plugins::checkload ( $pkgname = 'nagios-plugins-load', - $check_warning = hiera('nagios_load_warning', '15,10,5'), - $check_critical = hiera('nagios_load_critical', '30,25,20'), + $check_warning = hiera('nagios_load_warning', undef), + $check_critical = hiera('nagios_load_critical', undef), $contact_groups = $::environment, $max_check_attempts = $::icinga::max_check_attempts, $notification_period = $::icinga::notification_period, @@ -19,12 +19,30 @@ } } + if !$check_warning { + $warn_1 = $::processorcount * 3 + $warn_5 = $::processorcount * 2 + $warn_15 = $::processorcount + 1 + $_check_warning = "${warn_1},${warn_5},${warn_15}" + } else { + $_check_warning = $check_warning + } + + if !$check_critical { + $crit_1 = $::processorcount * 5 + $crit_5 = $::processorcount * 4 + $crit_15 = $::processorcount * 3 + $_check_critical = "${crit_1},${crit_5},${crit_15}" + } else { + $_check_critical = $check_critical + } + file{"${::icinga::includedir_client}/load.cfg": ensure => 'file', mode => '0644', owner => $::icinga::client_user, group => $::icinga::client_group, - content => "command[check_load]=${::icinga::plugindir}/check_load -w ${check_warning} -c ${check_critical}\n", + content => "command[check_load]=${::icinga::plugindir}/check_load -w ${_check_warning} -c ${_check_critical}\n", notify => Service[$::icinga::service_client], } diff --git a/manifests/plugins/checkmdraid.pp b/manifests/plugins/checkmdraid.pp index 0084439..7bd3a74 100644 --- a/manifests/plugins/checkmdraid.pp +++ b/manifests/plugins/checkmdraid.pp @@ -10,12 +10,12 @@ $notifications_enabled = $::icinga::notifications_enabled, ) inherits icinga { - file { "${::icinga::plugindir}/check_md_raid": + file { "${::icinga::plugindir}/check_md_raid": ensure => present, mode => '0755', owner => 'root', group => 'root', - source => 'puppet:///modules/icinga/check_md_raid', + source => 'puppet:///modules/icinga/check_md_raid', notify => Service[$icinga::service_client], require => Class['icinga::config']; } diff --git a/manifests/plugins/checkmdsbackend.pp b/manifests/plugins/checkmdsbackend.pp index b1f3a4a..e4a4fe7 100644 --- a/manifests/plugins/checkmdsbackend.pp +++ b/manifests/plugins/checkmdsbackend.pp @@ -16,7 +16,7 @@ mode => '0755', owner => 'root', group => 'root', - source => 'puppet:///modules/icinga/mds_backend.rb', + source => 'puppet:///modules/icinga/mds_backend.rb', notify => Service[$icinga::service_client], require => Class['icinga::config']; } diff --git a/manifests/plugins/checkmongodb.pp b/manifests/plugins/checkmongodb.pp index 64b67f4..358a588 100644 --- a/manifests/plugins/checkmongodb.pp +++ b/manifests/plugins/checkmongodb.pp @@ -12,20 +12,13 @@ $mongod_graphite_io_read_url = 'http://graphite/render?target=mongo_host.processes.mongod.ps_disk_octets.read&from=-5minutes&rawData=true', $mongod_graphite_io_write_url = 'http://graphite/render?target=mongo_host.processes.mongod.ps_disk_octets.write&from=-5minutes&rawData=true', $graphite_host = undef, -) inherits icinga { + $replica_set = undef, +) inherits icinga { if $icinga::client { - if !defined(Package['python-pip']) { - package { 'python-pip': - ensure => present, - } - } - - if !defined(Package['pymongo']) { - package { 'pymongo': + if !defined(Package['python-pymongo']) { + package { 'python-pymongo': ensure => present, - provider => 'pip', - require => Package['python-pip'], } } @@ -34,7 +27,7 @@ mode => '0755', owner => 'root', group => 'root', - source => 'puppet:///modules/icinga/check_mongodb.py', + source => 'puppet:///modules/icinga/check_mongodb.py', notify => Service[$icinga::service_client], require => Class['icinga::config']; } @@ -48,37 +41,51 @@ notify => Service[$::icinga::service_client], } - @@nagios_service { "check_mongodb_replication_lag_${::fqdn}": - check_command => 'check_nrpe_command!check_mongodb_replication_lag', - service_description => 'MongoDB Replication Lag', - host_name => $::fqdn, - contact_groups => $contact_groups, - notification_period => 'workhours', - notifications_enabled => $notifications_enabled, - max_check_attempts => $max_check_attempts, - target => "${::icinga::targetdir}/services/${::fqdn}.cfg", - } + if $replica_set { + @@nagios_service { "check_mongodb_replication_lag_${::fqdn}": + check_command => 'check_nrpe_command!check_mongodb_replication_lag', + service_description => 'MongoDB Replication Lag', + host_name => $::fqdn, + contact_groups => $contact_groups, + notification_period => 'workhours', + notifications_enabled => $notifications_enabled, + max_check_attempts => $max_check_attempts, + target => "${::icinga::targetdir}/services/${::fqdn}.cfg", + } - @@nagios_service { "check_mongodb_replication_lag_percentage_${::fqdn}": - check_command => 'check_nrpe_command!check_mongodb_replication_lag_percentage', - service_description => 'MongoDB Replication Lag Percentage', - host_name => $::fqdn, - contact_groups => $contact_groups, - notification_period => $notification_period, - notifications_enabled => $notifications_enabled, - max_check_attempts => $max_check_attempts, - target => "${::icinga::targetdir}/services/${::fqdn}.cfg", - } + @@nagios_service { "check_mongodb_replication_lag_percentage_${::fqdn}": + check_command => 'check_nrpe_command!check_mongodb_replication_lag_percentage', + service_description => 'MongoDB Replication Lag Percentage', + host_name => $::fqdn, + contact_groups => $contact_groups, + notification_period => $notification_period, + notifications_enabled => $notifications_enabled, + max_check_attempts => $max_check_attempts, + target => "${::icinga::targetdir}/services/${::fqdn}.cfg", + } + + @@nagios_service { "check_mongodb_replicaset_${::fqdn}": + check_command => 'check_nrpe_command!check_mongodb_replicaset', + service_description => 'MongoDB Replicaset', + host_name => $::fqdn, + contact_groups => $contact_groups, + notification_period => $notification_period, + notifications_enabled => $notifications_enabled, + max_check_attempts => $max_check_attempts, + target => "${::icinga::targetdir}/services/${::fqdn}.cfg", + } + + @@nagios_service { "check_mongodb_replset_state_${::fqdn}": + check_command => 'check_nrpe_command!check_mongodb_replset_state', + service_description => 'MongoDB Replication State', + host_name => $::fqdn, + contact_groups => $contact_groups, + notification_period => $notification_period, + notifications_enabled => $notifications_enabled, + max_check_attempts => $max_check_attempts, + target => "${::icinga::targetdir}/services/${::fqdn}.cfg", + } - @@nagios_service { "check_mongodb_replicaset_${::fqdn}": - check_command => 'check_nrpe_command!check_mongodb_replicaset', - service_description => 'MongoDB Replicaset', - host_name => $::fqdn, - contact_groups => $contact_groups, - notification_period => $notification_period, - notifications_enabled => $notifications_enabled, - max_check_attempts => $max_check_attempts, - target => "${::icinga::targetdir}/services/${::fqdn}.cfg", } @@nagios_service { "check_mongodb_connect_${::fqdn}": @@ -103,17 +110,6 @@ target => "${::icinga::targetdir}/services/${::fqdn}.cfg", } - @@nagios_service { "check_mongodb_replset_state_${::fqdn}": - check_command => 'check_nrpe_command!check_mongodb_replset_state', - service_description => 'MongoDB Replication State', - host_name => $::fqdn, - contact_groups => $contact_groups, - notification_period => $notification_period, - notifications_enabled => $notifications_enabled, - max_check_attempts => $max_check_attempts, - target => "${::icinga::targetdir}/services/${::fqdn}.cfg", - } - if $graphite_host != undef { @@nagios_service{"check_mongod_io_read_operations${::fqdn}": check_command => "check_graphite!${mongod_graphite_io_read_url}!10000000!50000000", diff --git a/manifests/plugins/checkmysqlclient.pp b/manifests/plugins/checkmysqlclient.pp new file mode 100644 index 0000000..3940087 --- /dev/null +++ b/manifests/plugins/checkmysqlclient.pp @@ -0,0 +1,40 @@ +# == Class: icinga::plugins::checkmysqlclient +# +define icinga::plugins::checkmysqlclient ( + $database, + $host, + $user, + $password = undef, + $hash = undef, + $contact_groups = $::environment, + $max_check_attempts = $::icinga::max_check_attempts, + $notification_period = $::icinga::notification_period, + $notifications_enabled = $::icinga::notifications_enabled, +) { + + require icinga + + if $password { + file { "${::icinga::includedir_client}/mysql_client_${database}-${user}.cfg": + ensure => 'file', + mode => '0644', + owner => $::icinga::client_user, + group => $::icinga::client_group, + notify => Service[$::icinga::service_client], + content => "command[check_mysql_${database}_${user}]=/usr/lib64/nagios/plugins/check_mysql -H ${host} -u ${user} -p ${password} -d ${database}" + } + + @@nagios_service { "check_mysql_client_${::fqdn}_${database}_${user}": + check_command => "check_nrpe_command!check_mysql_${database}_${user}", + service_description => "mysql client db: ${database} user: ${user}", + contact_groups => $contact_groups, + host_name => $::fqdn, + max_check_attempts => $max_check_attempts, + notification_period => $notification_period, + notifications_enabled => $notifications_enabled, + target => "${::icinga::targetdir}/services/${::fqdn}.cfg", + } + } + +} + diff --git a/manifests/plugins/checkmysqld.pp b/manifests/plugins/checkmysqld.pp index 45d8cfe..8662c59 100644 --- a/manifests/plugins/checkmysqld.pp +++ b/manifests/plugins/checkmysqld.pp @@ -3,13 +3,15 @@ # This class provides a checkmysqld plugin. # class icinga::plugins::checkmysqld ( - $ensure = present, - $perfdata = true, - $contact_groups = $::environment, - $max_check_attempts = $::icinga::max_check_attempts, - $notification_period = $::icinga::notification_period, - $notifications_enabled = $::icinga::notifications_enabled, - $mgmt_cnf = '/root/.my.cnf', + $ensure = present, + $perfdata = true, + $contact_groups = $::environment, + $max_check_attempts = $::icinga::max_check_attempts, + $notification_period = $::icinga::notification_period, + $notifications_enabled = $::icinga::notifications_enabled, + $connections_warning = 140, + $connections_critical = 150, + $mgmt_cnf = '/root/.my.cnf', ) inherits icinga { $pkg_nagios_plugins_mysqld = $::operatingsystem ? { @@ -37,15 +39,26 @@ owner => $::icinga::client_user, group => $::icinga::client_group, notify => Service[$::icinga::service_client], - content => "command[check_mysqld]=sudo ${::icinga::plugindir}/check_mysqld.pl -F ${mgmt_cnf}", + content => template('icinga/plugins/mysqld.cfg.erb'), } - @@nagios_service { "check_mysqld_performance_${::fqdn}": + Nagios_service { + host_name => $::fqdn, + contact_groups => $contact_groups, + max_check_attempts => $max_check_attempts, + notification_period => $notification_period, + notifications_enabled => $notifications_enabled, + target => "${::icinga::targetdir}/services/${::fqdn}.cfg", + } + + @@nagios_service { "check_mysqld_${::fqdn}": check_command => 'check_nrpe_command!check_mysqld', service_description => 'mysqld', - host_name => $::fqdn, - max_check_attempts => $max_check_attempts, - target => "${::icinga::targetdir}/services/${::fqdn}.cfg", + } + + @@nagios_service { "check_mysqld_connections_${::fqdn}": + check_command => 'check_nrpe_command!check_mysqld_connections', + service_description => 'mysqld connections', } sudo::conf{'nagios_mysqld_conf': @@ -53,7 +66,6 @@ nagios ALL=(ALL) NOPASSWD:${::icinga::plugindir}/check_mysqld.pl\n", } - if $perfdata { file { "${::icinga::includedir_client}/mysqld_performance.cfg": @@ -62,15 +74,6 @@ content => template('icinga/plugins/mysqld_performance.cfg.erb'); } - Nagios_service { - host_name => $::fqdn, - contact_groups => $contact_groups, - max_check_attempts => $max_check_attempts, - notification_period => $notification_period, - notifications_enabled => $notifications_enabled, - target => "${::icinga::targetdir}/services/${::fqdn}.cfg", - } - @@nagios_service { "check_mysqld_performance_1_${::fqdn}": check_command => 'check_nrpe_command!check_mysqld_performance_1', service_description => 'mysqld perf 1', @@ -162,4 +165,3 @@ } } } - diff --git a/manifests/plugins/checknginx.pp b/manifests/plugins/checknginx.pp new file mode 100644 index 0000000..813b4cf --- /dev/null +++ b/manifests/plugins/checknginx.pp @@ -0,0 +1,46 @@ +# == Class: icinga::plugins::checknginx +# +# This class provides a checknginx plugin. +# +class icinga::plugins::checknginx ( + $contact_groups = $::environment, + $max_check_attempts = $::icinga::max_check_attempts, + $notification_period = $::icinga::notification_period, + $notifications_enabled = $::icinga::notifications_enabled, +) inherits icinga { + + if $icinga::client { + file { "${::icinga::plugindir}/check_nginx": + ensure => present, + mode => '0755', + owner => 'root', + group => 'root', + seltype => 'nagios_admin_plugin_exec_t', + content => template ('icinga/plugins/check_nginx'), + notify => Service[$icinga::service_client], + require => Class['icinga::config']; + } + + file{"${::icinga::includedir_client}/nginx.cfg": + ensure => 'file', + mode => '0644', + owner => $::icinga::client_user, + group => $::icinga::client_group, + content => "command[check_nginx]=${::icinga::plugindir}/check_nginx -U 10.0.192.1:80 -P /bootstrap -w 300 -c 500\n", + notify => Service[$::icinga::service_client], + } + + @@nagios_service { "check_nginx_${::fqdn}": + check_command => 'check_nrpe_command!check_nginx', + service_description => 'Nginx', + host_name => $::fqdn, + contact_groups => $contact_groups, + max_check_attempts => $max_check_attempts, + notification_period => $notification_period, + notifications_enabled => $notifications_enabled, + target => "${::icinga::targetdir}/services/${::fqdn}.cfg", + } + } + +} + diff --git a/manifests/plugins/checkntp.pp b/manifests/plugins/checkntp.pp index b9c55f8..c789b9b 100644 --- a/manifests/plugins/checkntp.pp +++ b/manifests/plugins/checkntp.pp @@ -11,7 +11,7 @@ $max_check_attempts = $::icinga::max_check_attempts, $notification_period = $::icinga::notification_period, $notifications_enabled = $::icinga::notifications_enabled, -) inherits ::icinga { +) inherits icinga { if is_array($ntp_server) { $_ntp_server = $ntp_server[0] @@ -19,8 +19,6 @@ $_ntp_server = $ntp_server } - require ::ntp - file{"${::icinga::includedir_client}/ntp.cfg": ensure => 'file', mode => '0644', diff --git a/manifests/plugins/checkntpdhealth.pp b/manifests/plugins/checkntpdhealth.pp index 137fa87..40a14b2 100644 --- a/manifests/plugins/checkntpdhealth.pp +++ b/manifests/plugins/checkntpdhealth.pp @@ -11,9 +11,7 @@ $max_check_attempts = $::icinga::max_check_attempts, $notification_period = $::icinga::notification_period, $notifications_enabled = $::icinga::notifications_enabled, -) inherits ::icinga { - - require ::ntp +) inherits icinga { $script_path = "${::icinga::plugindir}/check_ntpd_health.pl" diff --git a/manifests/plugins/checkpercona-replication.pp b/manifests/plugins/checkpercona_replication.pp similarity index 88% rename from manifests/plugins/checkpercona-replication.pp rename to manifests/plugins/checkpercona_replication.pp index 982e172..1cd06f9 100644 --- a/manifests/plugins/checkpercona-replication.pp +++ b/manifests/plugins/checkpercona_replication.pp @@ -4,7 +4,7 @@ # # http://www.percona.com/doc/percona-monitoring-plugins/nagios/ # -class icinga::plugins::checkpercona-replication ( +class icinga::plugins::checkpercona_replication ( $ensure = present, $max_check_attempts = $::icinga::max_check_attempts, $notification_period = $::icinga::notification_period, @@ -48,9 +48,13 @@ notify => Service[$::icinga::service_client], } + sudo::conf{'nrpe_pmp-check-mysql-replication-running': + content => "Defaults:nagios !requiretty\nnagios ALL=(ALL) NOPASSWD:/usr/lib64/nagios/plugins/pmp-check-mysql-replication-running\n", + } + @@nagios_service { "check_percona_replication_running${::fqdn}": check_command => 'check_nrpe_command!check_percona_replication_running', service_description => 'Percona: Replication Running', } -} \ No newline at end of file +} diff --git a/manifests/plugins/checkpercona-replication-delay.pp b/manifests/plugins/checkpercona_replication_delay.pp similarity index 88% rename from manifests/plugins/checkpercona-replication-delay.pp rename to manifests/plugins/checkpercona_replication_delay.pp index dbafb4a..48989ac 100644 --- a/manifests/plugins/checkpercona-replication-delay.pp +++ b/manifests/plugins/checkpercona_replication_delay.pp @@ -4,7 +4,7 @@ # # http://www.percona.com/doc/percona-monitoring-plugins/nagios/ # -class icinga::plugins::checkpercona-replication-delay ( +class icinga::plugins::checkpercona_replication_delay ( $serverid = undef, $ensure = present, $max_check_attempts = $::icinga::max_check_attempts, @@ -51,6 +51,10 @@ notify => Service[$::icinga::service_client], } + sudo::conf{'nrpe_pmp-check-mysql-replication-delay': + content => "Defaults:nagios !requiretty\nnagios ALL=(ALL) NOPASSWD:/usr/lib64/nagios/plugins/pmp-check-mysql-replication-delay\n", + } + @@nagios_service { "check_percona_replication_delay${::fqdn}": check_command => 'check_nrpe_command!check_percona_replication_delay', service_description => 'Percona: Replication Delay', diff --git a/manifests/plugins/checkpuppet.pp b/manifests/plugins/checkpuppet.pp index 2fd1e52..2a668ae 100644 --- a/manifests/plugins/checkpuppet.pp +++ b/manifests/plugins/checkpuppet.pp @@ -26,10 +26,14 @@ mode => '0644', owner => $::icinga::client_user, group => $::icinga::client_group, - content => "command[check_puppet]=${::icinga::plugindir}/check_puppet -w 604800 -c 907200\n", + content => "command[check_puppet]=sudo ${::icinga::plugindir}/check_puppet -w 604800 -c 907200\n", notify => Service[$::icinga::service_client], } + sudo::conf{'nrpe_check_puppet': + content => "Defaults:nagios !requiretty\nnagios ALL=(ALL) NOPASSWD:${::icinga::plugindir}/check_puppet\n", + } + @@nagios_service { "check_puppet_${::fqdn}": check_command => 'check_nrpe_command!check_puppet', service_description => 'Puppet', diff --git a/manifests/plugins/checkrabbitmqsync.pp b/manifests/plugins/checkrabbitmqsync.pp new file mode 100644 index 0000000..6f04e38 --- /dev/null +++ b/manifests/plugins/checkrabbitmqsync.pp @@ -0,0 +1,36 @@ +# == Class: icinga::plugins::checkrabbitmqsync +define icinga::plugins::checkrabbitmqsync ( + $user, + $password, + $vhost = $name, + $host = 'localhost', + $port = '15672', + $contact_groups = $::environment, + $max_check_attempts = $::icinga::max_check_attempts, + $notification_period = $::icinga::notification_period, + $notifications_enabled = $::icinga::notifications_enabled, +) { + + require icinga + + file{"${::icinga::includedir_client}/check_rabbit_sync_${vhost}.cfg": + ensure => 'file', + mode => '0644', + owner => $::icinga::client_user, + group => $::icinga::client_group, + content => "command[check_rabbit_sync_${vhost}]=${::icinga::usrlib}/nagios/plugins/check_rabbitmq-sync.rb -h ${host} -u ${user} -p ${password} -P ${port} -v ${vhost}\n", + notify => Service[$::icinga::service_client], + } + + @@nagios_service{"check_rabbit_sync_${vhost}_${::fqdn}": + check_command => "check_nrpe_command!check_rabbit_sync_${vhost}", + service_description => "RabbitMQ node sync vhost: ${vhost}", + host_name => $::fqdn, + contact_groups => $contact_groups, + max_check_attempts => $max_check_attempts, + notification_period => $notification_period, + notifications_enabled => $notifications_enabled, + target => "${::icinga::targetdir}/services/${::fqdn}.cfg", + } + +} diff --git a/manifests/plugins/checkrsnapshot.pp b/manifests/plugins/checkrsnapshot.pp index 0acc7e3..07a1a1a 100644 --- a/manifests/plugins/checkrsnapshot.pp +++ b/manifests/plugins/checkrsnapshot.pp @@ -8,9 +8,9 @@ $max_check_attempts = $::icinga::max_check_attempts, $notification_period = 'workhours', $notifications_enabled = $::icinga::notifications_enabled, - $config = $::rsnapshot::params::config, + $config = hiera('rsnapshot::params::config', $::rsnapshot::params::config), $logfile = '/var/log/rsnapshot', - $crontabs = hiera('rsnapshot::params::crontabs'), + $crontabs = hiera('rsnapshot::params::crontabs', $::rsnapshot::params::crontabs), ) inherits icinga { $timeshift = $crontabs['daily']['hour'] @@ -19,7 +19,7 @@ mode => '0755', owner => 'root', group => 'root', - source => 'puppet:///modules/icinga/check_rsnapshot.rb', + source => 'puppet:///modules/icinga/check_rsnapshot.rb', notify => Service[$icinga::service_client], require => Class['icinga::config']; } diff --git a/manifests/plugins/checksmart.pp b/manifests/plugins/checksmart.pp index c24bba6..46dcd94 100644 --- a/manifests/plugins/checksmart.pp +++ b/manifests/plugins/checksmart.pp @@ -8,7 +8,6 @@ $max_check_attempts = $::icinga::max_check_attempts, $notification_period = $::icinga::notification_period, $notifications_enabled = $::icinga::notifications_enabled, - $smart_devices = hiera('smart_devices'), ) inherits icinga { package { 'smartmontools.x86_64': @@ -16,51 +15,51 @@ } - file { "${::icinga::plugindir}/check_smart.rb": - ensure => present, - mode => '0755', - owner => 'root', - group => 'root', - source => 'puppet:///modules/icinga/check_smart.rb', - notify => Service[$icinga::service_client], - require => Class['icinga::config']; - } - file { "${::icinga::plugindir}/check_smart.pl": - ensure => present, - mode => '0755', - owner => 'root', - group => 'root', - source => 'puppet:///modules/icinga/check_smart.pl', - notify => Service[$icinga::service_client], - require => Class['icinga::config']; - } + file { "${::icinga::plugindir}/check_smart.rb": + ensure => present, + mode => '0755', + owner => 'root', + group => 'root', + source => 'puppet:///modules/icinga/check_smart.rb', + notify => Service[$icinga::service_client], + require => Class['icinga::config']; + } - file { "${::icinga::includedir_client}/SMART.cfg": - ensure => 'file', - mode => '0644', - owner => $::icinga::client_user, - group => $::icinga::client_group, - content => template('icinga/plugins/SMART.cfg.erb'), - notify => Service[$::icinga::service_client], - } + file { "${::icinga::plugindir}/check_smart.pl": + ensure => present, + mode => '0755', + owner => 'root', + group => 'root', + source => 'puppet:///modules/icinga/check_smart.pl', + notify => Service[$icinga::service_client], + require => Class['icinga::config']; + } + file { "${::icinga::includedir_client}/SMART.cfg": + ensure => 'file', + mode => '0644', + owner => $::icinga::client_user, + group => $::icinga::client_group, + content => "#Managed by puppet\ncommand[check_smart]=sudo /usr/lib64/nagios/plugins/check_smart.rb", + notify => Service[$::icinga::service_client], + } - @@nagios_service { "check_smart_${::fqdn}": - check_command => 'check_nrpe_command!check_smart', - service_description => 'S.M.A.R.T.', - host_name => $::fqdn, - contact_groups => $contact_groups, - notification_period => $notification_period, - notifications_enabled => $notifications_enabled, - max_check_attempts => $max_check_attempts, - target => "${::icinga::targetdir}/services/${::fqdn}.cfg", - } + @@nagios_service { "check_smart_${::fqdn}": + check_command => 'check_nrpe_command!check_smart', + service_description => 'S.M.A.R.T.', + host_name => $::fqdn, + contact_groups => $contact_groups, + notification_period => $notification_period, + notifications_enabled => $notifications_enabled, + max_check_attempts => $max_check_attempts, + target => "${::icinga::targetdir}/services/${::fqdn}.cfg", + } - sudo::conf{'check_smart': + sudo::conf{'check_smart': content => "Defaults:nagios !requiretty - nagios ALL=(ALL) NOPASSWD:/usr/sbin/smartctl\n", - } - + nagios ALL=(ALL) NOPASSWD:${::icinga::plugindir}/check_smart.rb\n", } +} + diff --git a/manifests/plugins/checksslscan.pp b/manifests/plugins/checksslscan.pp new file mode 100644 index 0000000..03a7f21 --- /dev/null +++ b/manifests/plugins/checksslscan.pp @@ -0,0 +1,134 @@ +# == Class: icinga::plugins::checksslscan +# +# This defined type provides a checksslscan plugin. +# +define icinga::plugins::checksslscan ( + $host_url = undef, + $host_ip = undef, + $warning_grade = 'B', + $critical_grade = 'C', + $publish_results = false, + $accept_cached_results = true, + $max_cache_age = undef, + $debug_mode = false, + $max_check_attempts = $::icinga::max_check_attempts, + $contact_groups = $::environment, + $notification_period = $::icinga::notification_period, + $notifications_enabled = $::icinga::notifications_enabled, + $additional_options = '', + $icinga_host = hiera('icinga_host'), + $hour_range = hiera('hour_range', 7), + $hour_shift = hiera('hour_shift', 9), + +) { + + require icinga + + validate_string($host_url) + validate_string($warning_grade) + validate_string($critical_grade) + validate_bool($publish_results) + validate_bool($accept_cached_results) + validate_bool($debug_mode) + + if $publish_results { + $_publish_results = '-p ' + } else { + $_publish_results = '' + } + + if $accept_cached_results == false { + $_accept_cached_results = '-x ' + } else { + $_accept_cached_results = '' + } + + if $debug_mode { + $_debug_mode = '-d' + } else { + $_debug_mode = '' + } + + if $max_cache_age { + $_max_cache_age = "-a ${max_cache_age} " + } else { + $_max_cache_age = '' + } + + if $host_ip { + $_ip_address = "-ip ${host_ip} " + } else { + $_ip_address = '' + } + + if $icinga::client { + + if (!defined(Package['perl-JSON'])) { + package { 'perl-JSON': + ensure => installed, + } + } + + if (!defined(Package['perl-Crypt-SSLeay'])) { + package { 'perl-Crypt-SSLeay': + ensure => installed, + } + } + + if (!defined(Package['perl-Net-SSLeay'])) { + package { 'perl-Net-SSLeay': + ensure => installed, + } + } + + if (!defined(Package['nsca-client'])) { + package { 'nsca-client': + ensure => installed, + } + } + + + # Only include this file once + if (!defined(File["${::icinga::plugindir}/check_sslscan.pl"])) { + file { "${::icinga::plugindir}/check_sslscan.pl": + ensure => present, + mode => '0755', + owner => 'root', + group => 'root', + source => 'puppet:///modules/icinga/check_sslscan.pl', + notify => Service[$icinga::service_client], + require => Class['icinga::config']; + } + } + + file { "${::icinga::plugindir}/check_sslscan-${host_url}.sh": + ensure => 'file', + mode => '0755', + owner => $::icinga::client_user, + group => $::icinga::client_group, + content => template('icinga/plugins/check_sslscan.sh.erb'), + } + $hour = fqdn_rand($hour_range, $host_url) + $hour_shift + cron { "sslscan check-${host_url}": + ensure => present, + command => "${::icinga::plugindir}/check_sslscan-${host_url}.sh 2&>1 >/dev/null", + user => 'root', + hour => $hour, + minute => fqdn_rand(60, $host_url), + } + + @@nagios_service { "check_sslscan_${::fqdn}_${host_url}": + check_command => 'check_dummy!0 "All ok"', + active_checks_enabled => '0', + freshness_threshold => '600', + service_description => "SSL Quality ${host_url}", + host_name => $::fqdn, + contact_groups => $contact_groups, + notification_period => $notification_period, + notifications_enabled => $notifications_enabled, + max_check_attempts => $max_check_attempts, + target => "${::icinga::targetdir}/services/${::fqdn}.cfg", + } + } + +} diff --git a/manifests/plugins/checkstatsd.pp b/manifests/plugins/checkstatsd.pp index 0c2e008..39213f1 100644 --- a/manifests/plugins/checkstatsd.pp +++ b/manifests/plugins/checkstatsd.pp @@ -1,39 +1,40 @@ +# Class icinga::plugins::checkstatsd class icinga::plugins::checkstatsd ( - $ensure = present, + $ensure = present, $contact_groups = $::environment, $max_check_attempts = $::icinga::max_check_attempts, $notification_period = $::icinga::notification_period, $notifications_enabled = $::icinga::notifications_enabled, ) inherits icinga { - - file{"${::icinga::plugindir}/check_service.sh": - ensure => present, - mode => '0755', - owner => 'root', - group => 'root', - source => 'puppet:///modules/icinga/check_service.sh', - notify => Service[$icinga::service_client], - require => Class['icinga::config']; - } - file { "${::icinga::includedir_client}/check_statsd.cfg": - ensure => file, - mode => '0644', - owner => $::icinga::client_user, + file{"${::icinga::plugindir}/check_service.sh": + ensure => present, + mode => '0755', + owner => 'root', + group => 'root', + source => 'puppet:///modules/icinga/check_service.sh', + notify => Service[$icinga::service_client], + require => Class['icinga::config']; + } + + file { "${::icinga::includedir_client}/check_statsd.cfg": + ensure => file, + mode => '0644', + owner => $::icinga::client_user, group => $::icinga::client_group, content => template('icinga/plugins/check_statsd.cfg.erb'), notify => Service[$icinga::service_client], - } + } - @@nagios_service { "check_statsd_${::fqdn}": - check_command => 'check_nrpe_command!check_statsd', - service_description => 'Statsd status', - host_name => $::fqdn, + @@nagios_service { "check_statsd_${::fqdn}": + check_command => 'check_nrpe_command!check_statsd', + service_description => 'Statsd status', + host_name => $::fqdn, contact_groups => $contact_groups, notification_period => $notification_period, notifications_enabled => $notifications_enabled, max_check_attempts => $max_check_attempts, - target => "${::icinga::targetdir}/services/${::fqdn}.cfg", - } - -} \ No newline at end of file + target => "${::icinga::targetdir}/services/${::fqdn}.cfg", + } + +} diff --git a/manifests/plugins/checktopologylatency.pp b/manifests/plugins/checktopologylatency.pp new file mode 100644 index 0000000..d1fda4f --- /dev/null +++ b/manifests/plugins/checktopologylatency.pp @@ -0,0 +1,38 @@ +# == Class: icinga::plugins::checktopologylatency +class icinga::plugins::checktopologylatency ( + $host = 'localhost', + $port = 8888, + $critical_latency = 1200, + $warning_latency = 1000, + $contact_groups = $::environment, + $max_check_attempts = $::icinga::max_check_attempts, + $notification_period = $::icinga::notification_period, + $notifications_enabled = $::icinga::notifications_enabled, +) inherits ::icinga { + + package {'nagios-plugins-topology-latency': + ensure => present, + } + + file{"${::icinga::includedir_client}/topology_latency.cfg": + ensure => 'file', + mode => '0644', + owner => $::icinga::client_user, + group => $::icinga::client_group, + content => "command[check_storm_latency]=${::icinga::usrlib}/nagios/plugins/check_topology-latency.rb -h ${host} -p ${port} -w ${warning_latency} -c ${critical_latency}\n", + notify => Service[$::icinga::service_client], + } + + @@nagios_service{"check_collectiveaccess_${::fqdn}": + check_command => 'check_nrpe_command!check_storm_latency', + service_description => 'Storm Topology Latency', + host_name => $::fqdn, + contact_groups => $contact_groups, + max_check_attempts => $max_check_attempts, + notification_period => $notification_period, + notifications_enabled => $notifications_enabled, + target => "${::icinga::targetdir}/services/${::fqdn}.cfg", + } + +} + diff --git a/manifests/plugins/checktotalprocs.pp b/manifests/plugins/checktotalprocs.pp index 36d3c30..a4368b3 100644 --- a/manifests/plugins/checktotalprocs.pp +++ b/manifests/plugins/checktotalprocs.pp @@ -3,8 +3,6 @@ # This class provides a checktotalprocs plugin. # class icinga::plugins::checktotalprocs ( - $check_warning = '', - $check_critical = '', $contact_groups = $::environment, $max_check_attempts = $::icinga::max_check_attempts, $notification_period = $::icinga::notification_period, diff --git a/manifests/plugins/elasticsearch/check_number_of_documents.pp b/manifests/plugins/elasticsearch/check_number_of_documents.pp new file mode 100644 index 0000000..73842ec --- /dev/null +++ b/manifests/plugins/elasticsearch/check_number_of_documents.pp @@ -0,0 +1,56 @@ +# == Class: icinga::plugins::elasticsearch::check_number_of_documents +# +# This defined type provides a check of number of documents. When the number +# of documents is too low then you are alerted. +# +define icinga::plugins::elasticsearch::check_number_of_documents ( + $program_name, + $interval = '15 minutes ago', + $max_check_attempts = $::icinga::max_check_attempts, + $contact_groups = $::environment, + $notification_period = $::icinga::notification_period, + $notifications_enabled = $::icinga::notifications_enabled, +) { + + require icinga + + validate_string($interval) + validate_string($program_name) + + if $icinga::client { + + if (!defined(Package['jq'])) { + package { 'jq': + ensure => installed, + } + } + + file { "${::icinga::plugindir}/check_number_of_documents.sh": + ensure => present, + mode => '0755', + owner => $::icinga::client_user, + group => $::icinga::client_group, + source => "puppet:///modules/${module_name}/elasticsearch/check_number_of_documents.sh", + notify => Service[$icinga::service_client], + require => Class['icinga::config']; + } + + file { "${::icinga::includedir_client}/check_number_of_documents_${program_name}.cfg": + ensure => 'file', + mode => '0644', + owner => $::icinga::client_user, + group => $::icinga::client_group, + content => "command[check_number_of_documents_${program_name}]=${::icinga::plugindir}/check_number_of_documents.sh \$ARG1$ '\$ARG2$'", + notify => Service[$::icinga::service_client], + } + + @@nagios_service { "check_number_of_documents_${::fqdn}_${program_name}": + check_command => "check_nrpe_command_args!check_number_of_documents_${program_name}!${program_name} '${interval}'", + service_description => "ES data - occurrence counter of program: ${program_name}", + host_name => $::fqdn, + max_check_attempts => $max_check_attempts, + target => "${::icinga::targetdir}/services/${::fqdn}.cfg", + } + } + +} diff --git a/manifests/plugins/elasticsearch/readme.txt b/manifests/plugins/elasticsearch/readme.txt new file mode 100644 index 0000000..5fc01f5 --- /dev/null +++ b/manifests/plugins/elasticsearch/readme.txt @@ -0,0 +1,9 @@ +I created extra directory for all the checks which are related to Elasticsearch +querying. All the checks placed here should process the logs/documents +of applications. I feel that it's impossible to create one universal check so +it's better to create more checks which are mainly customer/appication specific. + +Do not move here the checks for Elasticsearch status itself. The are not related. + + +Any improvements are welcomed! Pavel (kayn) diff --git a/manifests/plugins/passivecheck.pp b/manifests/plugins/passivecheck.pp index fdfed3a..474a27e 100644 --- a/manifests/plugins/passivecheck.pp +++ b/manifests/plugins/passivecheck.pp @@ -10,13 +10,18 @@ $service_description = $title, $unique_id = "${title}-${::fqdn}", $freshness_threshold = 3600, + $contact_groups = $::environment, + $notification_period = $::icinga::notification_period, + $notifications_enabled = $::icinga::notifications_enabled, ){ @@nagios_service{ $unique_id: active_checks_enabled => 0, check_freshness => 1, freshness_threshold => $freshness_threshold, - notifications_enabled => $::icinga::notifications_enabled, + notifications_enabled => $notifications_enabled, + notification_period => $notification_period, + contact_groups => $contact_groups, passive_checks_enabled => 1, service_description => $service_description, host_name => $::fqdn, diff --git a/manifests/plugins/schedule_downtime_for_workhours.pp b/manifests/plugins/schedule_downtime_for_workhours.pp new file mode 100644 index 0000000..932bec1 --- /dev/null +++ b/manifests/plugins/schedule_downtime_for_workhours.pp @@ -0,0 +1,64 @@ +# == Class: icinga::plugins::schedule_downtime_for_workhours +# +# This class is kind of specific. +# +# We use aNag android app which does not have implemented feature which +# handles $notification_period at all. It means that even when you configure +# notification period to 'workhours', you will be notified in aNag app. +# +# So as a workaround, I created this class which will regularly check all +# the services and for services with 'workhours' will schedule downtime. +# +class icinga::plugins::schedule_downtime_for_workhours ( + $icinga_user = undef, + $icinga_pass = undef, + $icinga_url_services = 'http://localhost/icinga/cgi-bin/config.cgi?type=services&jsonoutput', + $icinga_url_hosts = 'http://localhost/icinga/cgi-bin/config.cgi?type=hosts&jsonoutput', + $work_dir = '/var/lib/icinga', + $downtimes = {}, +) inherits icinga { + + validate_hash($downtimes) + + file { '/usr/local/bin/get_services_with_workhours.py': + ensure => 'file', + mode => '0755', + owner => 'root', + group => 'root', + content => template('icinga/plugins/get_services_with_workhours.py.erb'), + } + + file { $work_dir: + ensure => 'directory', + mode => '0755', + owner => $::icinga::server_user, + group => $::icinga::server_group, + } + + cron { "${name}-cron-get-and-save-services-with-workhours": + command => "/usr/local/bin/get_services_with_workhours.py > ${work_dir}/workhours_downtimes.cfg", + user => 'root', + minute => '54', + } + + nagios_command {'schedule_downtime_for_workhours': + command_line => "${::icinga::sharedir_server}/bin/sched_down.pl -c ${::icinga::confdir_server}/icinga.cfg -s ${work_dir}/workhours_downtimes.cfg \$ARG1\$", + target => "${::icinga::targetdir}/commands/schedule_downtime_for_workhours.cfg", + } + + file {"${::icinga::targetdir}/commands/schedule_downtime_for_workhours.cfg": + ensure => 'present', + mode => '0600', + owner => $::icinga::server_user, + group => $::icinga::server_group, + } + + nagios_service {'schedule_downtime_for_workhours': + check_command => 'schedule_downtime_for_workhours!-d0', + service_description => 'Schedule downtimes for services with workhours', + host_name => $::fqdn, + target => "/etc/icinga/objects/services/${::fqdn}.cfg", + max_check_attempts => '4', + } + +} diff --git a/manifests/reports.pp b/manifests/reports.pp index 6f1ec81..666ec0e 100644 --- a/manifests/reports.pp +++ b/manifests/reports.pp @@ -17,12 +17,12 @@ class icinga::reports ( $db_module = 'percona', - $icingaReportsVersion = '1.10.0', - $icingaReportsHome = $::icinga::params::confdir_server, - $icingaAvailabilityFunctionName = 'icinga_availability', - $IdoDbName = $::icinga::params::idoutils_dbname, - $IdoDbUsername = $::icinga::params::idoutils_dbuser, - $IdoDbPassword = $::icinga::params::idoutils_dbpass, + $icinga_reports_version = '1.10.0', + $icinga_reports_home = $::icinga::params::confdir_server, + $icinga_availability_function_name = 'icinga_availability', + $ido_db_name = $::icinga::params::idoutils_dbname, + $ido_db_username = $::icinga::params::idoutils_dbuser, + $ido_db_password = $::icinga::params::idoutils_dbpass, ) inherits icinga { include tomcat6 @@ -50,9 +50,9 @@ package {'wget': ensure => 'installed'} } - $jasperHome = $jasperserver::jasperHome - $tomcatHome = $jasperserver::tomcatHome - $tomcatName = $tomcat6::params::tomcat_name + $jasper_home = $jasperserver::jasper_home + $tomcat_home = $jasperserver::tomcat_home + $tomcat_name = $tomcat6::params::tomcat_name # required for icinga-web connector php::module{ 'soap': } @@ -63,7 +63,7 @@ notify => Service[$::icinga::params::service_webserver], } - file { "${icingaReportsHome}/icinga-reports-${icingaReportsVersion}": + file { "${icinga_reports_home}/icinga-reports-${icinga_reports_version}": ensure => 'directory', owner => $::icinga::params::server_user, group => $::icinga::params::server_group, @@ -71,11 +71,11 @@ exec { 'get-icinga-reports': path => '/bin:/usr/bin:/sbin:/usr/sbin', - command => "/usr/bin/wget -O /tmp/icinga-reports-${icingaReportsVersion}.zip https://github.com/Icinga/icinga-reports/archive/v${icingaReportsVersion}.zip", + command => "/usr/bin/wget -O /tmp/icinga-reports-${icinga_reports_version}.zip https://github.com/Icinga/icinga-reports/archive/v${icinga_reports_version}.zip", timeout => 0, provider => 'shell', user => root, - unless => "test -d ${icingaReportsHome}/icinga-reports-${icingaReportsVersion}", + unless => "test -d ${icinga_reports_home}/icinga-reports-${icinga_reports_version}", require => Package['wget'], notify => Exec[unzip-icinga-reports], } @@ -83,7 +83,7 @@ exec { 'unzip-icinga-reports': refreshonly => true, path => '/bin:/usr/bin:/sbin:/usr/sbin', - command => "unzip -o -q /tmp/icinga-reports-${icingaReportsVersion}.zip -d ${icingaReportsHome}", + command => "unzip -o -q /tmp/icinga-reports-${icinga_reports_version}.zip -d ${icinga_reports_home}", require => Package['unzip'], notify => Exec['install-tomcat-mysql-connector'], } @@ -92,7 +92,7 @@ exec { 'install-tomcat-mysql-connector': refreshonly => true, path => '/bin:/usr/bin:/sbin:/usr/sbin', - command => "cp /usr/share/java/mysql-connector-java.jar ${tomcatHome}/lib/", + command => "cp /usr/share/java/mysql-connector-java.jar ${tomcat_home}/lib/", require => [ Package['mysql-connector-java'], Package['tomcat6'] ], notify => Exec['install-tomcat-mysql-connector-restart-tomcat'], } @@ -100,20 +100,20 @@ exec { 'install-tomcat-mysql-connector-restart-tomcat': refreshonly => true, path => '/bin:/usr/bin:/sbin:/usr/sbin', - command => "/etc/init.d/${tomcatName} restart", + command => "/etc/init.d/${tomcat_name} restart", require => Exec['install-tomcat-mysql-connector'], notify => Exec['js-import-icinga'], } exec { 'js-import-icinga': refreshonly => true, - command => "${jasperHome}/buildomatic/js-import.sh --input-zip ${icingaReportsHome}/icinga-reports-${icingaReportsVersion}/reports/icinga/package/js-icinga-reports.zip", + command => "${jasper_home}/buildomatic/js-import.sh --input-zip ${icinga_reports_home}/icinga-reports-${icinga_reports_version}/reports/icinga/package/js-icinga-reports.zip", require => [ Exec['install-tomcat-mysql-connector'], Package['tomcat6'], Anchor['jasperserver::end'] ], - cwd => "${icingaReportsHome}/icinga-reports-${icingaReportsVersion}", + cwd => "${icinga_reports_home}/icinga-reports-${icinga_reports_version}", notify => [Service['tomcat6'], Exec['install-jar-files']], } - file { "${tomcatHome}/webapps/jasperserver/WEB-INF/lib": + file { "${tomcat_home}/webapps/jasperserver/WEB-INF/lib": ensure => 'directory', require => [ Anchor['jasperserver::end'], Exec['js-import-icinga'] ] } @@ -121,17 +121,17 @@ exec { 'install-jar-files': refreshonly => true, path => '/bin:/usr/bin:/sbin:/usr/sbin', - command => "cp ${icingaReportsHome}/icinga-reports-${icingaReportsVersion}/jsp-server/classes/icinga/icinga-reporting.jar ${tomcatHome}/webapps/jasperserver/WEB-INF/lib/", - require => File["${tomcatHome}/webapps/jasperserver/WEB-INF/lib"], - cwd => "${icingaReportsHome}/icinga-reports-${icingaReportsVersion}", + command => "cp ${icinga_reports_home}/icinga-reports-${icinga_reports_version}/jsp-server/classes/icinga/icinga-reporting.jar ${tomcat_home}/webapps/jasperserver/WEB-INF/lib/", + require => File["${tomcat_home}/webapps/jasperserver/WEB-INF/lib"], + cwd => "${icinga_reports_home}/icinga-reports-${icinga_reports_version}", notify => [Service['tomcat6'], Exec['install-ido-icinga-availability-sql-function']], } exec { 'install-ido-icinga-availability-sql-function': refreshonly => true, path => '/bin:/usr/bin:/sbin:/usr/sbin', - unless => "mysql -u${IdoDbUsername} -p${IdoDbPassword} ${IdoDbName} -e 'select name from mysql.proc where name='${icingaAvailabilityFunctionName}';'", - command => "mysql -u${IdoDbUsername} -p${IdoDbPassword} ${IdoDbName} < ${icingaReportsHome}/icinga-reports-${icingaReportsVersion}/db/icinga/mysql/availability.sql", + unless => "mysql -u${ido_db_username} -p${ido_db_password} ${ido_db_name} -e 'select name from mysql.proc where name='${icinga_availability_function_name}';'", + command => "mysql -u${ido_db_username} -p${ido_db_password} ${ido_db_name} < ${icinga_reports_home}/icinga-reports-${icinga_reports_version}/db/icinga/mysql/availability.sql", require => [ Service[$db_service_name], Exec['install-jar-files'] ] } } diff --git a/manifests/user.pp b/manifests/user.pp index 1f88db1..791a3a0 100644 --- a/manifests/user.pp +++ b/manifests/user.pp @@ -38,7 +38,7 @@ if ! $hash { exec { "Add Icinga user ${name}": command => "htpasswd -b -s ${htpasswd} ${name} ${password}", - unless => "grep -iE '^${name}:' ${htpasswd}", + unless => "grep -q \"^$(htpasswd -s -b -n ${name} ${password} | head -n1)$\" ${htpasswd}", cwd => $::icinga::confdir_server, } } else { diff --git a/templates/common/commands.cfg.erb b/templates/common/commands.cfg.erb index d28be13..d690591 100644 --- a/templates/common/commands.cfg.erb +++ b/templates/common/commands.cfg.erb @@ -35,7 +35,7 @@ define command{ # 'notify-service-by-email' command definition define command{ command_name notify-service-by-email - command_line /usr/bin/printf "%b" "***** Icinga *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info: $SERVICEOUTPUT$\n\nComment: $SERVICEACKCOMMENT$\n" | <%= scope.lookupvar('icinga::mail_command') %> -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$ || logger "ERROR: icinga: e-mail notification failed" + command_line /usr/bin/printf "%b" "***** Icinga *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info: $SERVICEOUTPUT$\n\nAuthor: $SERVICEACKAUTHOR$\nComment: $SERVICEACKCOMMENT$\n" | <%= scope.lookupvar('icinga::mail_command') %> -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$ || logger "ERROR: icinga: e-mail notification failed" } @@ -60,6 +60,14 @@ define command{ command_line $USER1$/check_ping -H $HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 5 } +# 'check-host-alive-ipv4' command definition +# force use of ipv4 only because of issue with newer version of check_ping binary which in +# some cases prefers ipv6 even though it fails +define command{ + command_name check-host-alive-ipv4 + command_line $USER1$/check_ping -H $HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 5 -4 + } + @@ -195,6 +203,11 @@ define command{ command_line $USER1$/check_tcp -H $HOSTADDRESS$ -p $ARG1$ $ARG2$ } +# 'check_tcp' command definition +define command{ + command_name check_tcp_other_host + command_line $USER1$/check_tcp -H $ARG1$ -p $ARG2$ $ARG3$ +} # 'check_udp' command definition define command{ @@ -216,6 +229,11 @@ define command{ command_line $USER1$/check_dummy $ARG1$ } +define command{ + command_name check_generic + command_line $USER1$/$ARG1$ $ARG2$ +} + ################################################################################ # # SAMPLE PERFORMANCE DATA COMMANDS @@ -254,6 +272,11 @@ define command { command_line $USER1$/check_nrpe -t <%= scope.lookupvar('icinga::nrpe_command_timeout') %> -H $HOSTADDRESS$ -c $ARG1$ -a $ARG2$ } +define command { + command_name check_nrpe_4_args + command_line $USER1$/check_nrpe -t <%= scope.lookupvar('icinga::nrpe_command_timeout') %> -H $HOSTADDRESS$ -c $ARG1$ -a $ARG2$ $ARG3$ $ARG4$ $ARG5$ +} + define command { command_name tcp_nrpe command_line $USER1$/check_nrpe -t 60 -H $HOSTADDRESS$ diff --git a/templates/common/nrpe.cfg.erb b/templates/common/nrpe.cfg.erb index 58ad89d..410bafa 100644 --- a/templates/common/nrpe.cfg.erb +++ b/templates/common/nrpe.cfg.erb @@ -101,8 +101,8 @@ dont_blame_nrpe=<%= scope.lookupvar('icinga::nrpe_allow_arguments') %> # This lets the nagios user run all commands in that directory (and only them) # without asking for a password. If you do this, make sure you don't give # random users write access to that directory or its contents! -<% if scope.lookupvar('icinga::nrpe_command_prefix') != '' -%> -command_prefix=<%= scope.lookupvar('icinga::nrpe_command_prefix') -%> +<% if @nrpe_command_prefix -%> +command_prefix=<%= @nrpe_command_prefix -%> <% else -%> # command_prefix=/usr/bin/sudo <% end -%> @@ -195,4 +195,4 @@ command[check_total_procs]=<%= scope.lookupvar('icinga::usrlib') %>/nagios/plugi command[check_total_procs]=<%= scope.lookupvar('icinga::usrlib') %>/nagios/plugins/check_procs -w <%= scope.lookupvar('icinga::params::checktotalprocs_warning_level') %> -c <%= scope.lookupvar('icinga::params::checktotalprocs_critical_level') %> <% end -%> command[check_mem]=<%= scope.lookupvar('icinga::usrlib') %>/nagios/plugins/check_mem -w 90,25 -c 95,50 -command[check_ping]=<%= scope.lookupvar('icinga::usrlib') %>/nagios/plugins/check_ping -H $ARG1$ -4 -w $ARG2$ -c $ARG3$ -p 5 \ No newline at end of file +command[check_ping]=<%= scope.lookupvar('icinga::usrlib') %>/nagios/plugins/check_ping -H $ARG1$ -4 -w $ARG2$ -c $ARG3$ -p 5 diff --git a/templates/plugins/SMART.cfg.erb b/templates/plugins/SMART.cfg.erb deleted file mode 100644 index 789efd3..0000000 --- a/templates/plugins/SMART.cfg.erb +++ /dev/null @@ -1 +0,0 @@ -command[check_smart]=/usr/lib64/nagios/plugins/check_smart.rb <%="'"+Array(@smart_devices).join("' '")+"'" %> diff --git a/templates/plugins/check_cert_expiry.cfg.erb b/templates/plugins/check_cert_expiry.cfg.erb new file mode 100644 index 0000000..c2694d1 --- /dev/null +++ b/templates/plugins/check_cert_expiry.cfg.erb @@ -0,0 +1 @@ +command[check_local_cert_expiry_<%= @cert %>]=sudo /usr/lib64/nagios/plugins/check_ssl-cert -H localhost -f <%= @name %> -c <%= @critical_days %> -w <%= @warning_days %> --ignore-ocsp --ignore-sig-alg diff --git a/templates/plugins/check_nginx b/templates/plugins/check_nginx new file mode 100644 index 0000000..ddf14ed --- /dev/null +++ b/templates/plugins/check_nginx @@ -0,0 +1,108 @@ +# -*- coding: utf-8 -*- +#!/usr/bin/python +# check_nginx is a Nagios to monitor nginx status +# The version is 1.0.2 +# fixed by Nikolay Kandalintsev (twitter: @nicloay) +# Based on yangzi2008@126.com from http://www.nginxs.com +# which available here http://exchange.nagios.org/directory/Plugins/Web-Servers/nginx/check_nginx/details + +import string +import urllib2 +import getopt +import sys + +def usage(): + print """check_nginx is a Nagios to monitor nginx status + Usage: + + check_nginx [-h|--help][-U|--url][-P|--path][-u|--user][-p|--passwd][-w|--warning][-c|--critical] + + Options: + --help|-h) + print check_nginx help. + --url|-U) + Sets nginx status url. + --path|-P) + Sets nginx status url path. Default is: off + --user|-u) + Sets nginx status BasicAuth user. Default is: off + --passwd|-p) + Sets nginx status BasicAuth passwd. Default is: off + --warning|-w) + Sets a warning level for nginx Active connections. Default is: off + --critical|-c) + Sets a critical level for nginx Active connections. Default is: off + Example: + The url is www.nginxs.com/status + ./check_nginx -U www.nginxs.com -P /status -u eric -p nginx -w 1000 -c 2000 + if dont't have password: + ./check_nginx -U www.nginxs.com -P /status -w 1000 -c 2000 + if don't have path and password: + ./check_nginx -U www.nginxs.com -w 1000 -c 2000""" + + sys.exit(3) + +try: + options,args = getopt.getopt(sys.argv[1:],"hU:P:u:p:w:c:",["help","url=","path=","user=","passwd=","warning=","critical="]) + +except getopt.GetoptError: + usage() + sys.exit(3) + +for name,value in options: + if name in ("-h","--help"): + usage() + if name in ("-U","--url"): + url = "http://"+value + if name in ("-P","--path"): + path = value + if name in ("-u","--user"): + user = value + if name in ("-p","--passwd"): + passwd = value + if name in ("-w","--warning"): + warning = value + if name in ("-c","--critical"): + critical = value +try: + if 'path' in dir(): + req = urllib2.Request(url+path) + else: + req = urllib2.Request(url) + if 'user' in dir() and 'passwd' in dir(): + passman = urllib2.HTTPPasswordMgrWithDefaultRealm() + passman.add_password(None, url+path, user, passwd) + authhandler = urllib2.HTTPBasicAuthHandler(passman) + opener = urllib2.build_opener(authhandler) + urllib2.install_opener(opener) + response = urllib2.urlopen(req) + the_page = response.readline() + conn = the_page.split() + ActiveConn = conn[2] + the_page1 = response.readline() + the_page2 = response.readline() + the_page3 = response.readline() + response.close() + b = the_page3.split() + reading = b[1] + writing = b[3] + waiting = b[5] + output = 'ActiveConn:%s,reading:%s,writing:%s,waiting:%s' % (ActiveConn,reading,writing,waiting) + perfdata = 'ActiveConn:%s,reading:%s,writing:%s,waiting:%s' % (ActiveConn,reading,writing,waiting) + +except Exception: + print "NGINX STATUS unknown: Error while getting Connection" + sys.exit(3) +if 'warning' in dir() and 'critical' in dir(): + if int(ActiveConn) >= int(critical): + print 'CRITICAL - %s|%s' % (output,perfdata) + sys.exit(1) + elif int(ActiveConn) >= int(warning): + print 'WARNING - %s|%s' % (output,perfdata) + sys.exit(2) + else: + print 'OK - %s|%s' % (output,perfdata) + sys.exit(0) +else: + print 'OK - %s|%s' % (output,perfdata) + sys.exit(0) diff --git a/templates/plugins/check_rsnapshot.cfg.erb b/templates/plugins/check_rsnapshot.cfg.erb index 45b6abd..e5b43ec 100644 --- a/templates/plugins/check_rsnapshot.cfg.erb +++ b/templates/plugins/check_rsnapshot.cfg.erb @@ -1 +1,3 @@ -command[check_rsnapshot]=<%= @plugindir %>/check_rsnapshot.rb <%= @config %> <%= @logfile %> <%= @timeshift + 3 %> +# File managed by puppet +<% increased_timeshift = @timeshift.to_i + 3 -%> +command[check_rsnapshot]=<%= @plugindir %>/check_rsnapshot.rb <%= @config %> <%= @logfile %> <%= increased_timeshift.to_s %> diff --git a/templates/plugins/check_sslscan.sh.erb b/templates/plugins/check_sslscan.sh.erb new file mode 100644 index 0000000..5f60b15 --- /dev/null +++ b/templates/plugins/check_sslscan.sh.erb @@ -0,0 +1,11 @@ +#!/bin/bash +MSG=$(/usr/lib64/nagios/plugins/check_sslscan.pl -H <%= @host_url %> -w <%= @warning_grade %> -c <%= @critical_grade %>) +RET_VAL=$? +if [ $RET_VAL -eq 3 ]; then +# we probably got the "too many connections" error, we'll wait some time and try again + sleep $(($RANDOM % 800 + 240)) + MSG=$(/usr/lib64/nagios/plugins/check_sslscan.pl -H <%= @host_url %> -w <%= @warning_grade %> -c <%= @critical_grade %>) + RET_VAL=$? +fi +echo "<%= @fqdn %>;SSL Quality <%= @host_url %>;$RET_VAL;$MSG" | /usr/sbin/send_nsca -H <%= @icinga_host %> -p 5667 -d ";" + diff --git a/templates/plugins/cron_logs.cfg.erb b/templates/plugins/cron_logs.cfg.erb new file mode 100644 index 0000000..385c4aa --- /dev/null +++ b/templates/plugins/cron_logs.cfg.erb @@ -0,0 +1,5 @@ +<% if @ignored_jobs -%> +command[check_cron_logs]=sudo <%= scope.lookupvar('icinga::plugindir') %>/check_cron_logs.sh <%= Array(@ignored_jobs).join(' ') %> +<% else %> +command[check_cron_logs]=sudo <%= scope.lookupvar('icinga::plugindir') %>/check_cron_logs.sh +<% end -%> diff --git a/templates/plugins/dns_sync.cfg.erb b/templates/plugins/dns_sync.sh.erb similarity index 55% rename from templates/plugins/dns_sync.cfg.erb rename to templates/plugins/dns_sync.sh.erb index b6d0467..9aa2569 100644 --- a/templates/plugins/dns_sync.cfg.erb +++ b/templates/plugins/dns_sync.sh.erb @@ -1,3 +1,4 @@ +#!/bin/bash <% views=@full_zonelist.keys.select{ |i| i[/^view/] } -%> <% domains=[] -%> <% customers=[] -%> @@ -8,4 +9,7 @@ <% domains+= @full_zonelist[customer].keys -%> <% end -%> <% domains.map! {|domain| domain[/[^:]+/]} -%> -command[check_dns_sync]=/usr/lib64/nagios/plugins/check_dns_sync.pl -T1 <%= Array(domains).uniq.sort.join(" ") %> +MSG=$(/usr/lib64/nagios/plugins/check_dns_sync.pl -T 3 <%= (Array(domains)-Array(@ignored_domains)).uniq.sort.join(" ") %>) +RET_VAL=$? +echo "<%= @fqdn %>;dns sync;$RET_VAL;$MSG" | /usr/sbin/send_nsca -H <%= @icinga_host %> -p 5667 -d ";" + diff --git a/templates/plugins/get_services_with_workhours.py.erb b/templates/plugins/get_services_with_workhours.py.erb new file mode 100644 index 0000000..31196f4 --- /dev/null +++ b/templates/plugins/get_services_with_workhours.py.erb @@ -0,0 +1,59 @@ +#!/usr/bin/python + +import urllib2 +import json + +urlServices = '<%= @icinga_url_services %>' +urlHosts = '<%= @icinga_url_hosts %>' +username = '<%= @icinga_user %>' +password = '<%= @icinga_pass %>' + +passman = urllib2.HTTPPasswordMgrWithDefaultRealm() +passman.add_password(None, urlServices, username, password) +passman.add_password(None, urlHosts, username, password) +urllib2.install_opener(urllib2.build_opener(urllib2.HTTPBasicAuthHandler(passman))) + +req = urllib2.Request(urlServices) +f = urllib2.urlopen(req) +data = f.read() + +parsed_data = json.loads(data) + +print('# this output is generated by /usr/local/bin/get_services_with_workhours.py, probably by cron\n') + +for service in parsed_data['config']['services']: +<% @downtimes.each do |downtimes_key, downtimes_value_hash| -%> + if service['notification_period'] == '<%= downtimes_key -%>': + print('define downtime {') + print(" host_name %s " % (service['host_name']) ) + print(" service_description %s " % (service['service_description']) ) + print(' author <%= downtimes_value_hash['author'] -%>') + print(' comment <%= downtimes_value_hash['comment'] -%>') + <%- downtimes_value_hash['downtime_period'].each do |dtperiod| -%> + print(' downtime_period <%= dtperiod -%>') + <%- end -%> + print(' propagate 1') + print(' register 1') + print('}\n') +<% end -%> + +req = urllib2.Request(urlHosts) +f = urllib2.urlopen(req) +data = f.read() + +parsed_data = json.loads(data) + +for host in parsed_data['config']['hosts']: +<% @downtimes.each do |downtimes_key, downtimes_value_hash| -%> + if host['notification_period'] == '<%= downtimes_key -%>': + print('define downtime {') + print(" host_name %s " % (host['host_name']) ) + print(' author <%= downtimes_value_hash['author'] -%>') + print(' comment <%= downtimes_value_hash['comment'] -%>') + <%- downtimes_value_hash['downtime_period'].each do |dtperiod| -%> + print(' downtime_period <%= dtperiod -%>') + <%- end -%> + print(' propagate 1') + print(' register 1') + print('}\n') +<% end -%> diff --git a/templates/plugins/haproxy.cfg.erb b/templates/plugins/haproxy.cfg.erb index 94530a7..a5c6dcb 100644 --- a/templates/plugins/haproxy.cfg.erb +++ b/templates/plugins/haproxy.cfg.erb @@ -3,4 +3,4 @@ ### Module: '<%= scope.to_hash['module_name'] %>' ### Template source: '<%= template_source %>' -command[check_haproxy]=<%= @plugindir %>/check_haproxy.rb -u localhost -U <%= @username %> -P <%= @password %> +command[check_haproxy]=<%= @plugindir %>/check_haproxy.rb -u '$ARG1$' 2>/dev/null diff --git a/templates/plugins/mongodb.cfg.erb b/templates/plugins/mongodb.cfg.erb index 9e65047..f233cd0 100644 --- a/templates/plugins/mongodb.cfg.erb +++ b/templates/plugins/mongodb.cfg.erb @@ -3,9 +3,11 @@ ### Module: '<%= scope.to_hash['module_name'] %>' ### Template source: '<%= template_source %>' -command[check_mongodb_replication_lag]=<%= @plugindir %>/check_mongodb.py -H <%= @mongod_bind_ip %> -A replication_lag -P 27017 -W 15 -C 30 -command[check_mongodb_replication_lag_percentage]=<%= @plugindir %>/check_mongodb.py -H <%= @mongod_bind_ip %> -A replication_lag_percent -P 27017 -W 50 -C 75 -command[check_mongodb_replicaset]=<%= @plugindir %>/check_mongodb.py -H <%= @mongod_bind_ip %> -A replica_primary -P 27017 -W 0 -C 1 command[check_mongodb_connect]=<%= @plugindir %>/check_mongodb.py -H <%= @mongod_bind_ip %> -A connect -P 27017 -W 2 -C 4 command[check_mongodb_connections]=<%= @plugindir %>/check_mongodb.py -H <%= @mongod_bind_ip %> -A connections -P 27017 -W 70 -C 80 +<% if @replica_set -%> +command[check_mongodb_replication_lag]=<%= @plugindir %>/check_mongodb.py -H <%= @mongod_bind_ip %> -A replication_lag -P 27017 -W 15 -C 30 +command[check_mongodb_replication_lag_percentage]=<%= @plugindir %>/check_mongodb.py -H <%= @mongod_bind_ip %> -A replication_lag_percent -P 27017 -W 50 -C 75 +command[check_mongodb_replicaset]=<%= @plugindir %>/check_mongodb.py -H <%= @mongod_bind_ip %> -A replica_primary -P 27017 -W 0 -C 1 -r <%= @replica_set %> command[check_mongodb_replset_state]=<%= @plugindir %>/check_mongodb.py -H <%= @mongod_bind_ip %> -A replset_state -P 27017 +<% end -%> diff --git a/templates/plugins/mysqld.cfg.erb b/templates/plugins/mysqld.cfg.erb new file mode 100644 index 0000000..a4f8752 --- /dev/null +++ b/templates/plugins/mysqld.cfg.erb @@ -0,0 +1,5 @@ +# +# Managed by Puppet +# +command[check_mysqld]=sudo <%= scope.lookupvar('icinga::plugindir') %>/check_mysqld.pl -F <%= scope.lookupvar('icinga::plugins::checkmysqld::mgmt_cnf') %> +command[check_mysqld_connections]=sudo <%= scope.lookupvar('icinga::plugindir') %>/check_mysqld.pl -F <%= scope.lookupvar('icinga::plugins::checkmysqld::mgmt_cnf') %> -f -a threads_connected -w <%= scope.lookupvar('icinga::plugins::checkmysqld::connections_warning') %> -c <%= scope.lookupvar('icinga::plugins::checkmysqld::connections_critical') %> diff --git a/templates/plugins/mysqld_performance.cfg.erb b/templates/plugins/mysqld_performance.cfg.erb index 294c69c..5bedb78 100644 --- a/templates/plugins/mysqld_performance.cfg.erb +++ b/templates/plugins/mysqld_performance.cfg.erb @@ -7,7 +7,7 @@ command[check_mysqld_performance_2]=sudo <%= scope.lookupvar('icinga::plugindir' command[check_mysqld_performance_3]=sudo <%= scope.lookupvar('icinga::plugindir') %>/check_mysqld.pl -F <%= scope.lookupvar('icinga::plugins::checkmysqld::mgmt_cnf') %> -f -A binlog_cache_disk_use,binlog_cache_use command[check_mysqld_performance_4]=sudo <%= scope.lookupvar('icinga::plugindir') %>/check_mysqld.pl -F <%= scope.lookupvar('icinga::plugins::checkmysqld::mgmt_cnf') %> -f -A bytes_received,bytes_sent,connections command[check_mysqld_performance_5]=sudo <%= scope.lookupvar('icinga::plugindir') %>/check_mysqld.pl -F <%= scope.lookupvar('icinga::plugins::checkmysqld::mgmt_cnf') %> -f -A created_tmp_disk_tables,created_tmp_files,created_tmp_tables -command[check_mysqld_performance_6]=sudo <%= scope.lookupvar('icinga::plugindir') %>/check_mysqld.pl -F <%= scope.lookupvar('icinga::plugins::checkmysqld::mgmt_cnf') %> -f -A elayed_errors,delayed_insert_threads,delayed_writes +command[check_mysqld_performance_6]=sudo <%= scope.lookupvar('icinga::plugindir') %>/check_mysqld.pl -F <%= scope.lookupvar('icinga::plugins::checkmysqld::mgmt_cnf') %> -f -A delayed_errors,delayed_insert_threads,delayed_writes command[check_mysqld_performance_7]=sudo <%= scope.lookupvar('icinga::plugindir') %>/check_mysqld.pl -F <%= scope.lookupvar('icinga::plugins::checkmysqld::mgmt_cnf') %> -f -A handler_update,handler_write,handler_delete,handler_read_first,handler_read_key,handler_read_next,handler_read_prev,handler_read_rnd,handler_read_rnd_next command[check_mysqld_performance_8]=sudo <%= scope.lookupvar('icinga::plugindir') %>/check_mysqld.pl -F <%= scope.lookupvar('icinga::plugins::checkmysqld::mgmt_cnf') %> -f -A key_blocks_not_flushed,key_blocks_unused,key_blocks_used,key_read_requests,key_reads,key_write_requests,key_writes command[check_mysqld_performance_9]=sudo <%= scope.lookupvar('icinga::plugindir') %>/check_mysqld.pl -F <%= scope.lookupvar('icinga::plugins::checkmysqld::mgmt_cnf') %> -f -A max_used_connections diff --git a/templates/redhat/icinga.cfg.erb b/templates/redhat/icinga.cfg.erb index 86c2111..87f8f31 100644 --- a/templates/redhat/icinga.cfg.erb +++ b/templates/redhat/icinga.cfg.erb @@ -248,6 +248,7 @@ event_broker_options=-1 #broker_module=/somewhere/module2.o arg1 arg2=3 debug=0 + <%- if @use_ido -%> broker_module=/usr/lib64/icinga/idomod.so config_file=/etc/icinga/idomod.cfg <% end %> @@ -256,6 +257,13 @@ broker_module=/usr/lib64/icinga/idomod.so config_file=/etc/icinga/idomod.cfg broker_module=/usr/local/lib/flapjackfeeder.o redis_host=10.0.64.34,redis_port=6380 <% end %> +<% if @use_livestatus and not @use_ido and not @use_flapjackfeeder %> +broker_module=/usr/lib64/mk-livestatus/livestatus.o /tmp/live.sock +<% end %> + + + + # LOG ROTATION METHOD # This is the log rotation method that Icinga should use to rotate # the main log file. Values are as follows.. @@ -297,7 +305,7 @@ use_syslog=1 # If you enabled use_syslog you can set icinga to use a local facility # instead of the default.To enable set this option to 1, if not, set it to 0. -use_syslog_local_facility=0 +use_syslog_local_facility=1 @@ -361,7 +369,7 @@ log_initial_states=0 # checks - see the option below for controlling whether or not # passive checks are logged. -log_external_commands=1 +log_external_commands=0 @@ -370,7 +378,7 @@ log_external_commands=1 # this value to 0. If passive checks should be logged, set # this value to 1. -log_passive_checks=1 +log_passive_checks=0 @@ -1138,7 +1146,7 @@ high_host_flap_threshold=20.0 # strict-iso8601 (YYYY-MM-DDTHH:MM:SS) # -date_format=us +date_format=iso8601