lib/Monitoring/Reporter/Backend/NagiosLivestatus.pm

filter: Statementstmt 28.1% 20 / 71 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 25.0% 4 / 16 Podpod 87.5% 7 / 8 totaltotal 31.3% 31 / 99 CC 5 SCAR 21.7
CC
5
Cov
27%
triggers
30.0
_init_lsc
2.0
_init_mapping
2.0
CRAP 8.8
« lib/Monitoring/Reporter/Web/Plugin/History.pm ↑ Summary lib/Monitoring/Reporter/Backend.pm »
1 package Monitoring::Reporter::Backend::NagiosLivestatus;
2 {
3 1 $Monitoring::Reporter::Backend::NagiosLivestatus::VERSION = '0.01';
4 }
5 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 $Monitoring::Reporter::Backend::NagiosLivestatus::AUTHORITY = 'cpan:TEX';
7 }
8 # ABSTRACT: Monitoring dashboard Nagios Backend
9  
10 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 ▶use Monitoring::Livestatus;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 has 'lsc' => (
16 'is' => 'rw',
17 'isa' => 'Monitoring::Livestatus',
18 'lazy' => 1,
19 'builder' => '_init_lsc',
20 );
21  
22 1 has '_mapping' => (
23 'is' => 'ro',
24 'isa' => 'HashRef',
25 'lazy' => 1,
26 'builder' => '_init_mapping',
27 );
28  
29 1 has '_severity_mapping' => (
30 'is' => 'ro',
31 'isa' => 'HashRef',
32 'lazy' => 1,
33 'builder' => '_init_severity_mapping',
34 );
35  
36 1 has '_priority_mapping' => (
37 'is' => 'ro',
38 'isa' => 'HashRef',
39 'lazy' => 1,
40 'builder' => '_init_priority_mapping',
41 );
42  
43 1 extends 'Monitoring::Reporter::Backend';
44  
45 1 with qw(Config::Yak::RequiredConfig Log::Tree::RequiredLogger);
46  
47 0 ▶sub _init_lsc {
Subroutine _init_lsc: not called CC=1 SCAR=6.9
48 0 my $self = shift;
49  
50 0 my $lsc_peer = $self->config()->get( 'Monitoring::Reporter::Backend::'.$self->name().'::Peer', { Default => '/var/lib/nagios3/rw/livestatus.sock', }, );
51  
52 0 $self->logger()->log( message => 'Using LSC Peer: '.$lsc_peer, level => 'debug', );
53  
54 0 my $LSC = Monitoring::Livestatus::->new(
55 'peer' => $lsc_peer,
56 'warnings' => 0,
57 'verbose' => 0,
58 );
59  
60 0 return $LSC;
61 }
62  
63 0 ▶sub _init_mapping {
Subroutine _init_mapping: not called CC=1 SCAR=6.9
64 0 my $self = shift;
65  
66 0 my $Mapping = {
67 'priority' => 'last_state',
68 'host' => 'host_display_name',
69 'description' => 'plugin_output',
70 'hostid' => undef,
71 'triggerid' => undef,
72 'itemid' => undef,
73 'lastvalue' => 'plugin_output',
74 'lastclock' => 'last_state_change',
75 'lastchange' => 'last_time_ok',
76 'value' => 'plugin_output',
77 'comments' => undef,
78 'units' => undef,
79 'valuemapid' => undef,
80 'triggerpid' => undef,
81 };
82  
83 0 return $Mapping;
84 }
85  
86 0 ▶sub _init_priority_mapping {
Subroutine _init_priority_mapping: not called CC=1 SCAR=6.9
87 0 my $self = shift;
88  
89 0 my $PrioMapping = {
90 '0' => '1', # OK -> information
91 '1' => '4', # WARNING -> High
92 '2' => '5', # CRITICAL -> Disaster
93 };
94 0 return $PrioMapping;
95 }
96  
97 0 ▶sub _init_severity_mapping {
Subroutine _init_severity_mapping: not called CC=1 SCAR=6.9
98 0 my $self = shift;
99  
100 0 my $SevMapping = {
101 '0' => 'information',
102 '1' => 'high',
103 '2' => 'disaster',
104 };
105  
106 0 return $SevMapping;
107 }
108  
109 0 ▶sub fetch {
Subroutine fetch: not called CC=1 SCAR=6.9
Pod documented
110 0 my $self = shift;
111 0 my $query = shift;
112 0 my @args = @_;
113  
114 0 my $refs = $self->lsc()->selectall_arrayref($query, { Slice => {}, });
115  
116 0 return $refs;
117 }
118  
119 0 ▶sub do {
Subroutine do: not called CC=1 SCAR=6.9
Pod undocumented
120 0 my $self = shift;
121 0 my $query = shift;
122 0 my @args = @_;
123  
124 0 return $self->lsc()->do($query, @args);
125 }
126  
127 0 ▶sub triggers {
Subroutine triggers: not called CC=5 SCAR=34.0
Pod documented
128 0 my $self = shift;
129  
130 0 my @rows = ();
131  
132 0 $self->logger()->log( message => 'Nagios-Triggers', level => 'debug', );
133  
134 #my $arr_refs = $self->fetch_n_store('GET services');
135 0 my $arr_refs = $self->fetch('GET services');
136  
137 0 foreach my $e (@{$arr_refs}) {
138 #print "Host: ".$e->{'host_display_name'}." - ".$e->{'description'}." - ".$e->{'plugin_output'}." - ".$e->{'last_state'}." - ".$e->{'last_time_ok'}."\n";
139 0 my $row = {};
140 0 foreach my $to (keys %{$self->_mapping()}) {
141 0 my $from = $self->_mapping()->{$to};
142 0 ▶ if(defined($from)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $from) { } 0 0 0
143 0 ▶ if($to eq 'priority') {
Branch: 1 branch
BranchTrueFalseTotal
if ($to eq 'priority') { } 0 0 0
144 0 $row->{$to} = $self->_priority_mapping()->{$e->{$from}};
145 0 $row->{'severity'} = $self->_severity_mapping()->{$e->{$from}};
146 } else {
147 0 $row->{$to} = $e->{$from};
148 }
149 } else {
150 0 $row->{$to} = 0;
151 }
152 }
153 0 push(@rows, $row);
154 }
155  
156 0 return \@rows;
157 }
158  
159 0 ▶sub disabled_actions {
Subroutine disabled_actions: not called CC=1 SCAR=6.9
Pod documented
160 0 my $self = shift;
161  
162 0 return []; # TODO not supported?
163 }
164  
165 0 ▶sub enable_actions {
Subroutine enable_actions: not called CC=1 SCAR=6.9
Pod documented
166 0 my $self = shift;
167  
168 0 return []; # TODO not supported?
169 }
170  
171 0 ▶sub unsupported_items {
Subroutine unsupported_items: not called CC=1 SCAR=6.9
Pod documented
172 0 my $self = shift;
173  
174 0 return []; # TODO not supported?
175 }
176  
177 0 ▶sub unattended_alarms {
Subroutine unattended_alarms: not called CC=1 SCAR=6.9
Pod documented
178 0 my $self = shift;
179
180 0 return []; # TODO not supported
181 }
182  
183 0 ▶sub history {
Subroutine history: not called CC=1 SCAR=6.9
Pod documented
184 0 my $self = shift;
185  
186 0 return []; # TODO not supported?
187 }
188 1 __PACKAGE__->meta->make_immutable;
189  
190 1 1; # End of Monitoring::Reporter
191  
192 __END__
« lib/Monitoring/Reporter/Web/Plugin/History.pm ↑ Summary lib/Monitoring/Reporter/Backend.pm »