Created
June 10, 2014 12:54
-
-
Save lazyfrosch/c184f4b02be509b6e8ee to your computer and use it in GitHub Desktop.
Verify Icinga Freshness Settings via objects.cache
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/perl | |
| use strict; | |
| use warnings; | |
| use Data::Dumper; | |
| my $file = 'objects.cache'; | |
| open(OBJECTCACHE, "<", $file) or die "could not open '$file': $!"; | |
| my $count_services = 0; | |
| my $count_actives = 0; | |
| my $count_passives = 0; | |
| my $count_passiveswithfresh = 0; | |
| my $count_disabled = 0; | |
| my $warnings = 0; | |
| my $in_service = 0; | |
| #my $SERVICES = (); | |
| my $service = (); | |
| while(<OBJECTCACHE>) { | |
| my $line = $_; | |
| if ($line =~ m/define\s+service\s+{/) { | |
| $service = (); | |
| $in_service = 1; | |
| $count_services++; | |
| } | |
| # write service object to hash | |
| elsif ($in_service == 1 and $line =~ m/^\s*}\s*$/) { | |
| if (defined $service->{service_description} and defined $service->{host_name}) { | |
| my $name = sprintf("%s-%s", $service->{host_name}, $service->{service_description}); | |
| #$SERVICES->{$name} = $service; | |
| ### | |
| # checks | |
| ### | |
| if ($service->{active_checks_enabled} == 1) { | |
| $count_actives++; | |
| } | |
| elsif ($service->{passive_checks_enabled} == 1) { | |
| $count_passives++; | |
| if ($service->{check_freshness} == 1) { | |
| $count_passiveswithfresh++; | |
| my $threshold = int($service->{freshness_threshold}); | |
| my $interval = int($service->{check_interval}); | |
| $threshold = $threshold / 60; | |
| if ($interval > $threshold) { | |
| $warnings++; | |
| print STDERR "WARNING: $name - freshness threshold is too low (interval: $interval, threshold: $threshold)\n"; | |
| } | |
| } | |
| } | |
| else { | |
| $count_disabled++; | |
| } | |
| } else { | |
| print STDERR "ERROR: service_description or host_name missing in service object!\n"; | |
| print Dumper($service); | |
| } | |
| $in_service = 0; | |
| } | |
| elsif ($in_service == 1) { | |
| if ($line =~ m/\s*([\w_]+)\s+(.+)\s*$/) { | |
| my $attr = $1; | |
| my $val = $2; | |
| if ($attr =~ m/^host_name|service_description|(active|passive)_checks_enabled|check_freshness|check_interval|freshness_threshold$/) { | |
| $service->{$attr} = $val; | |
| } | |
| } | |
| } | |
| } | |
| close(OBJECTCACHE); | |
| printf "Found %d services in total\n", $count_services; | |
| print "\n"; | |
| printf "active checks: %d\n", $count_actives; | |
| printf "passive checks: %d\n", $count_passives; | |
| printf "freshness check: %d\n", $count_passiveswithfresh; | |
| printf "disabled checks: %d\n", $count_disabled; | |
| print "\n"; | |
| printf "warnings: %d\n", $warnings; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment