This file is indexed.

/usr/share/perl5/MMM/Monitor/ChecksStatus.pm is in mysql-mmm-monitor 2.2.1-1.1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package MMM::Monitor::ChecksStatus;
use base 'Class::Singleton';

use strict;
use warnings FATAL => 'all';
use Log::Log4perl qw(:easy);
use MMM::Monitor::Checker

our $VERSION = '0.01';

sub _new_instance($) {
	my $class = shift;

	my $data = {};

	my @checks		= keys(%{$main::config->{check}});
	my @hosts		= keys(%{$main::config->{host}});

	foreach my $host_name (@hosts) {
		$data->{$host_name} = {};
	}

	my $time = time();

	# Perform initial checks
	INFO 'Performing initial checks...';
	foreach my $check_name (@checks) {

		# Spawn checker
		my $checker = new MMM::Monitor::Checker::($check_name);

		# Check all hosts
		foreach my $host_name (@hosts) {
			DEBUG "Trying initial check '$check_name' on host '$host_name'";
			my $res = $checker->check($host_name);
			DEBUG "$check_name($host_name) = '$res'";
			$data->{$host_name}->{$check_name} = {};
			$data->{$host_name}->{$check_name}->{status}      = ($res =~ /^OK/)? 1 : 0;
			$data->{$host_name}->{$check_name}->{last_change} = $time;
			$data->{$host_name}->{$check_name}->{message}     = $res;
		}

		# Shutdown checker
		$checker->shutdown();
	}
	return bless $data, $class; 
}


=item handle_result(MMM::Monitor::CheckResult $result)

handle the results of a check and change state accordingly

=cut

sub handle_result($$) {
	my $self = shift;
	my $result = shift;

	# always save the latest message, but don't override time of last change
	$self->{$result->{host}}->{$result->{check}}->{message}     = $result->{message};
	return if ($result->{result} == $self->{$result->{host}}->{$result->{check}}->{status}); 

	$self->{$result->{host}}->{$result->{check}}->{status}      = $result->{result};
	$self->{$result->{host}}->{$result->{check}}->{last_change} = time();
}

=item ping($host)

Get state of check "ping" on host $host.

=cut

sub ping($$) {
	my $self = shift;
	my $host = shift;
	return $self->{$host}->{ping}->{status};
}


=item ping($host)

Get state of check "mysql" on host $host.

=cut

sub mysql($$) {
	my $self = shift;
	my $host = shift;
	return $self->{$host}->{mysql}->{status};
}


=item rep_threads($host)

Get state of check "rep_threads" on host $host.

=cut

sub rep_threads($$) {
	my $self = shift;
	my $host = shift;
	return $self->{$host}->{rep_threads}->{status};
}


=item rep_backlog($host)

Get state of check "rep_backlog" on host $host.

=cut

sub rep_backlog($$) {
	my $self = shift;
	my $host = shift;
	return $self->{$host}->{rep_backlog}->{status};
}


=item last_change($host, [$check])

Get time of last state change

=cut

sub last_change {
	my $self  = shift;
	my $host  = shift;
	my $check = shift || undef;

	return $self->{$host}->{$check}->{last_change} if (defined($check));

	my $time = $self->{$host}->{ping}->{last_change};
	$time = $self->{$host}->{mysql}->{last_change}       if ($self->{$host}->{mysql}->{last_change}       > $time);
	$time = $self->{$host}->{rep_threads}->{last_change} if ($self->{$host}->{rep_threads}->{last_change} > $time);
	$time = $self->{$host}->{rep_backlog}->{last_change} if ($self->{$host}->{rep_backlog}->{last_change} > $time);
	return $time;
}


=item message($host, $check)

Get time of last state change

=cut

sub message($$$) {
	my $self  = shift;
	my $host  = shift;
	my $check = shift;
	return $self->{$host}->{$check}->{message};
}

1;