| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package App::OverWatch; |
|
2
|
|
|
|
|
|
|
# ABSTRACT: Watch over your infrastructure |
|
3
|
6
|
|
|
6
|
|
3088
|
use strict; |
|
|
6
|
|
|
|
|
7
|
|
|
|
6
|
|
|
|
|
198
|
|
|
4
|
6
|
|
|
6
|
|
23
|
use warnings; |
|
|
6
|
|
|
|
|
8
|
|
|
|
6
|
|
|
|
|
142
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
6
|
|
|
6
|
|
1925
|
use App::OverWatch::DB; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use App::OverWatch::ServiceLock; |
|
8
|
|
|
|
|
|
|
use App::OverWatch::EventLog; |
|
9
|
|
|
|
|
|
|
use App::OverWatch::Notify; |
|
10
|
|
|
|
|
|
|
use App::OverWatch::Config; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use Config::Tiny; |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
|
15
|
|
|
|
|
|
|
my $class = shift; |
|
16
|
|
|
|
|
|
|
my $rh_options = shift || {}; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my $self = bless( {}, $class ); |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
return $self; |
|
21
|
|
|
|
|
|
|
} |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub servicelock { |
|
25
|
|
|
|
|
|
|
my $self = shift; |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
if (!defined($self->{ServiceLock})) { |
|
28
|
|
|
|
|
|
|
$self->{ServiceLock} = App::OverWatch::ServiceLock->new({ |
|
29
|
|
|
|
|
|
|
db => $self->_db() |
|
30
|
|
|
|
|
|
|
}); |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
return $self->{ServiceLock}; |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub notify { |
|
36
|
|
|
|
|
|
|
my $self = shift; |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
if (!defined($self->{Notify})) { |
|
39
|
|
|
|
|
|
|
$self->{Notify} = App::OverWatch::Notify->new({ |
|
40
|
|
|
|
|
|
|
db => $self->_db() |
|
41
|
|
|
|
|
|
|
}); |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
return $self->{Notify}; |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub eventlog { |
|
47
|
|
|
|
|
|
|
my $self = shift; |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
if (!defined($self->{Eventlog})) { |
|
50
|
|
|
|
|
|
|
$self->{Eventlog} = App::OverWatch::Eventlog->new({ |
|
51
|
|
|
|
|
|
|
db => $self->_db() |
|
52
|
|
|
|
|
|
|
}); |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
return $self->{Eventlog}; |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub check_options { |
|
58
|
|
|
|
|
|
|
my $self = shift; |
|
59
|
|
|
|
|
|
|
my $rh_args = shift || {}; |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
my $ra_commands = $rh_args->{valid_commands}; |
|
62
|
|
|
|
|
|
|
my $rh_options = $rh_args->{options}; |
|
63
|
|
|
|
|
|
|
my $rh_required = $rh_args->{required_options}; |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
## Check that only one actual command was provided |
|
66
|
|
|
|
|
|
|
my $commands = join(', ', sort @$ra_commands); |
|
67
|
|
|
|
|
|
|
my @commands = map { $rh_options->{$_} ? $_ : () } @$ra_commands; |
|
68
|
|
|
|
|
|
|
die "Error: Please specify one and only one command ($commands)\n" |
|
69
|
|
|
|
|
|
|
if (scalar @commands != 1); |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
my $command = $commands[0]; |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
## Check all required options are defined |
|
74
|
|
|
|
|
|
|
for my $opt (@{ $rh_required->{$command} }) { |
|
75
|
|
|
|
|
|
|
die "Error: --$opt is a required option\n" |
|
76
|
|
|
|
|
|
|
if (!defined($rh_options->{$opt})); |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
return $command; |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub load_config { |
|
83
|
|
|
|
|
|
|
my $self = shift; |
|
84
|
|
|
|
|
|
|
my $path = shift; |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
my $rh_conf; |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
my @paths; |
|
89
|
|
|
|
|
|
|
if (defined($path)) { |
|
90
|
|
|
|
|
|
|
@paths = ( $path ); |
|
91
|
|
|
|
|
|
|
} else { |
|
92
|
|
|
|
|
|
|
@paths = ( $ENV{HOME} . "/.overwatch.conf", |
|
93
|
|
|
|
|
|
|
"/etc/overwatch.conf" ); |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
FILE: |
|
97
|
|
|
|
|
|
|
for my $file (@paths) { |
|
98
|
|
|
|
|
|
|
next FILE |
|
99
|
|
|
|
|
|
|
if (!defined($file) || ! -f $file); |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
my $Config = Config::Tiny->read($file); |
|
102
|
|
|
|
|
|
|
$rh_conf = $Config->{_} |
|
103
|
|
|
|
|
|
|
if ($Config && defined($Config->{_})); |
|
104
|
|
|
|
|
|
|
} |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
die "Error: Couldn't load configuration from " |
|
107
|
|
|
|
|
|
|
. join(', ', @paths) . "\n" |
|
108
|
|
|
|
|
|
|
if (!defined($rh_conf)); |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
die "Error: Require 'db_type' to be set in config\n" |
|
111
|
|
|
|
|
|
|
if (!$rh_conf->{db_type}); |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
$self->{Config} = App::OverWatch::Config->new($rh_conf); |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub load_config_string { |
|
117
|
|
|
|
|
|
|
my $self = shift; |
|
118
|
|
|
|
|
|
|
my $string = shift; |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
my $Config = Config::Tiny->read_string($string); |
|
121
|
|
|
|
|
|
|
my $rh_conf = $Config->{_} |
|
122
|
|
|
|
|
|
|
if ($Config && defined($Config->{_})); |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
die "Error: Couldn't load configuration from string\n" |
|
125
|
|
|
|
|
|
|
if (!defined($rh_conf)); |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
die "Error: Require 'db_type' to be set in config\n" |
|
128
|
|
|
|
|
|
|
if (!$rh_conf->{db_type}); |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
$self->{Config} = App::OverWatch::Config->new($rh_conf); |
|
131
|
|
|
|
|
|
|
} |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub _db { |
|
134
|
|
|
|
|
|
|
my $self = shift; |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
if (!defined($self->{DB})) { |
|
137
|
|
|
|
|
|
|
$self->{DB} = App::OverWatch::DB->new( $self->{Config} ); |
|
138
|
|
|
|
|
|
|
} |
|
139
|
|
|
|
|
|
|
return $self->{DB}; |
|
140
|
|
|
|
|
|
|
} |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
1; |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
__END__ |