Created
August 30, 2019 10:32
-
-
Save seidler2547/4d63b47c4504fe7f884a80efc6ae1a7d to your computer and use it in GitHub Desktop.
Icinga 2 plugins
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
my $currentkernel = `uname -r`; | |
chomp($currentkernel); | |
`ls -t1 /boot/vmlinuz-* | head -1` =~ q!^/boot/vmlinuz-(.+)$!; | |
my $latestkernel = $1; | |
chomp($latestkernel); | |
if ($currentkernel eq '' || $latestkernel eq '') { | |
print "UNKNOWN, could not determine kernel version, current=\"$currentkernel\", latest=\"$latestkernel.\"\n"; | |
exit(3); | |
} | |
if ($currentkernel eq $latestkernel) { | |
`uname -v` =~ /([0-9]\.[0-9]+\.[0-9]+\-[^ ]+)/; | |
my $curexactkernel = $1; | |
my $instexactkernel = `/usr/bin/dpkg-query -W -f='\${Version}' linux-image-$currentkernel 2>/dev/null`; | |
if ($?) { | |
$instexactkernel = $curexactkernel; | |
} else { | |
chomp($instexactkernel); | |
} | |
if ($curexactkernel eq $instexactkernel) { | |
print "OK, running kernel $currentkernel ($curexactkernel).\n"; | |
exit(0); | |
} | |
print "CRITICAL, running kernel $curexactkernel but installed is $instexactkernel.\n"; | |
exit(2); | |
} | |
if ($currentkernel lt $latestkernel) { | |
print "CRITICAL, running kernel $currentkernel but latest is $latestkernel.\n"; | |
exit(2); | |
} | |
if ($currentkernel gt $latestkernel) { | |
print "CRITICAL, running kernel $currentkernel but latest is $latestkernel.\n"; | |
exit(1); | |
} | |
print "UNKNOWN, current=\"$currentkernel\", latest=\"$latestkernel\".\n"; | |
exit(3); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use JSON qw(decode_json); | |
use Data::Dumper; | |
my $ignored = "noout.+"; | |
my $cephoutput = `\$(which sudo) ceph -s --format=json`; | |
$cephoutput =~ s/^\s+|\s+$//g; | |
my $ceph = decode_json($cephoutput); | |
my @health_issues = (); | |
my $max_severity = 0; | |
my $status = 3; | |
#print Dumper($ceph); | |
foreach $hi (keys %{$ceph->{health}->{checks}}) { | |
my $item = $ceph->{health}->{checks}->{$hi}; | |
my $message = $item->{summary}->{message}; | |
next if $message =~ m/$ignored/; | |
#print '# '.$hi.": ".$message." ".$item->{severity}."\n"; | |
$max_severity = 1 if $item->{severity} eq 'HEALTH_WARN'; | |
$max_severity = 2 if $item->{severity} eq 'HEALTH_CRIT'; | |
push(@health_issues, $message); | |
} | |
my $osdmap = $ceph->{osdmap}->{osdmap}; | |
if (($osdmap->{num_in_osds} < $osdmap->{num_osds} || $osdmap->{num_up_osds} < $osdmap->{num_osds}) && $status < 2) { | |
$max_severity = 2; | |
push(@health_issues, 'not all OSDs up or in'); | |
} | |
if ($osdmap->{full}) { | |
$max_severity = 2; | |
push(@health_issues, 'full OSDs'); | |
} | |
if ($osdmap->{nearfull}) { | |
$max_severity = 1 if $max_severity < 2; | |
push(@health_issues, 'nearfull OSDs'); | |
} | |
if (@health_issues == 0 and $ceph->{health}->{overall_status}) { | |
$status = 0; | |
} | |
my $pgmap = $ceph->{pgmap}; | |
my %pgstates; | |
foreach $pg (@{$pgmap->{pgs_by_state}}) { | |
#print Dumper($pg)."\n"; | |
foreach $pgstate (split(/\+/, $pg->{state_name})) { | |
$pgstates{$pgstate} += $pg->{count}; | |
} | |
} | |
#print Dumper(%pgstates); | |
if ($pgstates{'degraded'} + $pgstates{'backfill_toofull'} + $pgstates{'recovery_toofull'} + $pgstates{'down'} > 1) { | |
$max_severity = 2; | |
} | |
if ($max_severity > 1) { | |
$status = 2; | |
} elsif ($max_severity > 0) { | |
$status = 1; | |
} | |
my $message = ''; | |
if ($status == 0) { | |
$message .= 'OK'; | |
} elsif ($status == 1) { | |
$message .= 'WARNING'; | |
} elsif ($status == 2) { | |
$message .= 'CRITICAL'; | |
} else { | |
$message .= 'UNKNOWN'; | |
} | |
if (@health_issues == 0) { | |
push(@health_issues, $ceph->{health}->{overall_status}); | |
} | |
$message .= ': '.join(', ', @health_issues); | |
$message .= ', OSDs: '.$osdmap->{num_in_osds}.'/'.$osdmap->{num_up_osds}.'/'.$osdmap->{num_osds}; | |
$message .= "|"; | |
foreach $st (keys(%pgstates)) { | |
$message .= "pg_$st=".$pgstates{$st}.";;; "; | |
} | |
foreach $pgd (keys(%{$pgmap})) { | |
next if ref($pgmap->{$pgd}); | |
$message .= "$pgd=".$pgmap->{$pgd}; | |
$message .= 'B' if $pgd =~ m/bytes$/ || $pgd =~ m/^bytes/; | |
$message .= '%' if $pgd =~ m/ratio$/; | |
$message .= ';;; '; | |
} | |
$message .= "\n"; | |
print $message; | |
exit($status); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/awk -E | |
BEGIN { | |
while ((getline <"/proc/meminfo") > 0 ) { | |
gsub(/:/,""); | |
gsub(/\(/,"_"); | |
gsub(/\)/,""); | |
a[$1]=$2; | |
u[$1]=toupper($3); | |
} | |
swapfactor=(ENVIRON["swapfactor"]~/^[0-9]+$/)?ENVIRON["swapfactor"]:0.5; | |
critical=(ENVIRON["critical"]~/^[0-9]+$/)?ENVIRON["critical"]:10; | |
warning=(ENVIRON["warning"]~/^[0-9]+$/)?ENVIRON["warning"]:20; | |
} | |
END { | |
ma=a["MemAvailable"]; | |
mt=a["MemTotal"]; | |
sf=a["SwapFree"]; | |
if (mt<10000 || ma<10) exit 3; | |
mr=100*(ma+(sf*swapfactor))/mt; | |
ec=0; | |
printf "Memory "; | |
if (mr<critical) { printf "CRITICAL"; ec=2; } else | |
if (mr<warning) { printf "WARNING"; ec=1; } else | |
printf "OK"; | |
printf ", %.1f%% (%d/%d MB + %d MB swap) available|",(ma*100/mt),(ma/1024),(mt/1024),(sf/1024); | |
for (k in a) printf k"="a[k]u[k]";;; "; | |
print ""; | |
exit ec; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/opt/puppetlabs/puppet/bin/ruby | |
require 'yaml' | |
require 'puppet' | |
require 'optparse' | |
options = { | |
:lastrun_warn => 3600, | |
:lastrun_crit => 36000, | |
:runtime_warn => 25, | |
:runtime_crit => 60, | |
} | |
OptionParser.new do |opt| | |
opt.banner = "Usage: #{$0} [options]" | |
opt.on('-l', '--lastrun w,c', Array, 'Time since last Puppet run') { |w| options[:lastrun_warn] = w[0].to_i; options[:lastrun_crit] = w[1].to_i } | |
opt.on('-r', '--runtime w,c', Array, 'Total Puppet run time') { |w| options[:runtime_warn] = w[0].to_i; options[:runtime_crit] = w[1].to_i } | |
end.parse! | |
report = YAML.load_file('/opt/puppetlabs/puppet/cache/state/last_run_report.yaml') | |
overall = 3; | |
if (report.status == 'unchanged') | |
overall = 0 | |
message = 'No changes' | |
elsif (report.status == 'failed') | |
overall = 2 | |
message = 'Failed resources' | |
else | |
overall = 1 | |
message = 'Changed resources' | |
end | |
lastrun = Time.now.to_i - Time.at(report.time).to_i | |
if (overall < 2) | |
if (lastrun > options[:lastrun_crit]) | |
overall = 2 | |
message << ", Last run: #{lastrun}" | |
end | |
if (report.metrics['time']['total'] > options[:runtime_crit]) | |
overall = 2 | |
message << ", Total run time: #{report.metrics['time']['total']}" | |
end | |
end | |
if (overall < 1) | |
if (lastrun > options[:lastrun_warn]) | |
overall = 1 | |
message << ", Last run: #{lastrun}" | |
end | |
if (report.metrics['time']['total'] > options[:runtime_warn]) | |
overall = 1 | |
message << ", Total run time: #{report.metrics['time']['total']}" | |
end | |
end | |
case overall | |
when 2 | |
print 'CRITICAL' | |
when 1 | |
print 'WARNING' | |
when 0 | |
print 'OK' | |
else | |
print 'UNKNOWN' | |
end | |
print ', %s|lastrun=%i;%i;%i;0; ' % [ message, lastrun, options[:lastrun_warn], options[:lastrun_crit] ] | |
if !report.metrics.empty? | |
for met in [ 'total', 'skipped', 'failed', 'failed_to_restart', 'restarted', 'changed', 'out_of_sync', 'scheduled' ] | |
print "res_#{met}=#{report.metrics['resources'][met]};;;0; " | |
end | |
puts "runtime=#{report.metrics['time']['total']}s;#{options[:runtime_warn]};#{options[:runtime_crit]};0; " | |
end | |
exit overall |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment