lib/Monitoring/Reporter/Web/Plugin/Demo.pm

filter: Statementstmt 60.4% 26 / 43 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 72.7% 8 / 11 Podpod 100% 1 / 1 totaltotal 54.6% 35 / 64 CC 5 SCAR 23.8
CC
5
Cov
51%
execute
30.0
_init_fields
2.0
_init_alias
2.0
CRAP 10.8
« lib/Monitoring/Reporter/Web.pm ↑ Summary lib/Monitoring/Reporter/Web/Plugin/History.pm »
1 package Monitoring::Reporter::Web::Plugin::Demo;
2 {
3 1 $Monitoring::Reporter::Web::Plugin::Demo::VERSION = '0.01';
4 }
5 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 $Monitoring::Reporter::Web::Plugin::Demo::AUTHORITY = 'cpan:TEX';
7 }
8 # ABSTRACT: List a set of demo triggers to showcase the interfaces and tweak the UI
9  
10 1 ▶use 5.010_000;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use mro 'c3';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use feature ':5.10';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 # use IO::Handle;
18 # use autodie;
19 # use MooseX::Params::Validate;
20 # use Carp;
21 # use English qw( -no_match_vars );
22 # use Try::Tiny;
23 1 ▶use Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 # extends ...
26 1 extends 'Monitoring::Reporter::Web::Plugin';
27 # has ...
28 # with ...
29 # initializers ...
30 0 ▶sub _init_fields { return [qw(refresh acked allgood)]; }
Subroutine _init_fields: not called CC=1 SCAR=6.9
31  
32 0 ▶sub _init_alias { return 'demo_triggers'; }
Subroutine _init_alias: not called CC=1 SCAR=6.9
33  
34 # your code here ...
35 0 ▶sub execute {
Subroutine execute: not called CC=5 SCAR=34.0
Pod documented
36 0 my $self = shift;
37 0 my $request = shift;
38  
39 0 my $triggers = [
40 {
41 'severity' => 'disaster',
42 'host' => 'samplehost.example.org',
43 'description' => 'DNS Down',
44 'lastchange' => '1368300364',
45 'comments' => 'This shows a nameserver which is unreachable',
46 },
47 {
48 'severity' => 'high',
49 'host' => 'samplehost.example.org',
50 'description' => 'Webserver Down',
51 'lastchange' => '1368300364',
52 'comments' => 'This shows a webserver which is unreachable',
53 },
54 {
55 'severity' => 'average',
56 'host' => 'samplehost.example.org',
57 'description' => 'Webserver Down',
58 'lastchange' => '1368300364',
59 'comments' => 'This shows a webserver which is unreachable',
60 },
61 {
62 'severity' => 'warning',
63 'host' => 'samplehost.example.org',
64 'description' => 'HDD almost full',
65 'lastchange' => '1368300364',
66 'comments' => 'This shows a HDD which is almost full',
67 },
68 {
69 'severity' => 'information',
70 'host' => 'samplehost.example.org',
71 'description' => '/etc/passwd was just changed',
72 'lastchange' => '1368300364',
73 'comments' => 'This shows a webserver which is unreachable',
74 },
75 {
76 'severity' => 'nc',
77 'host' => 'samplehost.example.org',
78 'description' => 'Webserver Down',
79 'lastchange' => '1368300364',
80 'comments' => 'This shows a webserver which is unreachable',
81 },
82 ];
83 0 my $triggers_acked = [
84 {
85 'severity' => 'disaster',
86 'host' => 'samplehost.example.org',
87 'description' => 'DNS Down',
88 'lastchange' => '1368300364',
89 'comments' => 'This shows a nameserver which is unreachable',
90 'acknowledged' => 1,
91 },
92 {
93 'severity' => 'high',
94 'host' => 'samplehost.example.org',
95 'description' => 'Webserver Down',
96 'lastchange' => '1368300364',
97 'comments' => 'This shows a webserver which is unreachable',
98 'acknowledged' => 1,
99 },
100 {
101 'severity' => 'average',
102 'host' => 'samplehost.example.org',
103 'description' => 'Webserver Down',
104 'lastchange' => '1368300364',
105 'comments' => 'This shows a webserver which is unreachable',
106 'acknowledged' => 1,
107 },
108 {
109 'severity' => 'warning',
110 'host' => 'samplehost.example.org',
111 'description' => 'HDD almost full',
112 'lastchange' => '1368300364',
113 'comments' => 'This shows a HDD which is almost full',
114 'acknowledged' => 1,
115 },
116 {
117 'severity' => 'information',
118 'host' => 'samplehost.example.org',
119 'description' => '/etc/passwd was just changed',
120 'lastchange' => '1368300364',
121 'comments' => 'This shows a webserver which is unreachable',
122 'acknowledged' => 1,
123 },
124 {
125 'severity' => 'nc',
126 'host' => 'samplehost.example.org',
127 'description' => 'Webserver Down',
128 'lastchange' => '1368300364',
129 'comments' => 'This shows a webserver which is unreachable',
130 'acknowledged' => 1,
131 },
132 ];
133 0 ▶ my $refresh = $request->{'refresh'} || 30;
Condition0%0/2
$request->{'refresh'} || 30
l!l
00
MC/DC0%0/1
$request->{'refresh'} || 30
$request->{'refresh'}
Truth table0%0/2
A
A= $request->{'refresh'}
Aresult
11
00
134  
135 # include acked triggers
136 0 ▶ if($request->{'acked'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($request->{"acked"}) 0 0 0
137 0 @{$triggers} = (@{$triggers},@{$triggers_acked});
138 }
139  
140 # show OK sign
141 0 ▶ if($request->{'allgood'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($request->{"allgood"}) 0 0 0
142 0 $triggers = [];
143 }
144  
145 0 my $body;
146 0 ▶ $self->tt()->process(
Branch: 1 branch
BranchTrueFalseTotal
$self->tt->process("list_triggers.tpl", {"triggers", $triggers, "refresh", $refresh}, \$body) or $self->logger->log("message", 'TT error: ' . $self->tt->error, "level", "warning") 0 0 0
147 'list_triggers.tpl',
148 {
149 'triggers' => $triggers,
150 'refresh' => $refresh,
151 },
152 \$body,
153 ) or $self->logger()->log( message => 'TT error: '.$self->tt()->error, level => 'warning', );
154  
155 0 return [ 200, [ 'Content-Type', 'text/html' ], [$body] ];
156 }
157  
158 1 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
159 1 __PACKAGE__->meta->make_immutable;
160  
161 1 1;
162  
163 __END__
« lib/Monitoring/Reporter/Web.pm ↑ Summary lib/Monitoring/Reporter/Web/Plugin/History.pm »