File Coverage

blib/lib/WWW/DNSMadeEasy/Monitor.pm
Criterion Covered Total %
statement 9 57 15.7
branch 0 10 0.0
condition n/a
subroutine 3 34 8.8
pod 29 30 96.6
total 41 131 31.3


line stmt bran cond sub pod time code
1             package WWW::DNSMadeEasy::Monitor;
2             our $VERSION = '0.100';
3             our $AUTHORITY = 'cpan:GETTY';
4             # ABSTRACT: DNS Failover and System Monitoring configuration
5              
6 8     8   57 use Moo;
  8         18  
  8         80  
7 8     8   3525 use String::CamelSnakeKebab qw/lower_camel_case/;
  8         22  
  8         53  
8              
9 8     8   2361 use feature qw/say/;
  8         19  
  8         12805  
10              
11             has dme => (is => 'ro', required => 1, handles => ['request']);
12             has record => (is => 'ro', required => 1, handles => {path => 'monitor_path'});
13             has as_hashref => (is => 'rw', builder => 1, lazy => 1, clearer => 1);
14             has response => (is => 'rw');
15              
16 0     0     sub _build_as_hashref { shift->response->as_hashref }
17              
18 0     0 1   sub auto_failover { shift->as_hashref->{autoFailover} }
19 0     0 1   sub contact_list_id { shift->as_hashref->{contactListId} }
20 0     0 1   sub failover { shift->as_hashref->{failover} }
21 0     0 1   sub http_file { shift->as_hashref->{httpFile} }
22 0     0 1   sub http_fqdn { shift->as_hashref->{httpFqdn} }
23 0     0 1   sub http_query_string { shift->as_hashref->{httpQueryString} }
24 0     0 1   sub ip1 { shift->as_hashref->{ip1} }
25 0     0 1   sub ip1_failed { shift->as_hashref->{ip1Failed} }
26 0     0 1   sub ip2 { shift->as_hashref->{ip2} }
27 0     0 1   sub ip2_failed { shift->as_hashref->{ip2Failed} }
28 0     0 1   sub ip3 { shift->as_hashref->{ip3} }
29 0     0 1   sub ip3_failed { shift->as_hashref->{ip3Failed} }
30 0     0 1   sub ip4 { shift->as_hashref->{ip4} }
31 0     0 1   sub ip4_failed { shift->as_hashref->{ip4Failed} }
32 0     0 1   sub ip5 { shift->as_hashref->{ip5} }
33 0     0 1   sub ip5_failed { shift->as_hashref->{ip5Failed} }
34 0     0 1   sub max_emails { shift->as_hashref->{maxEmails} }
35 0     0 1   sub monitor { shift->as_hashref->{monitor} }
36 0     0 1   sub port { shift->as_hashref->{port} }
37 0     0 1   sub protocol_id { shift->as_hashref->{protocolId} }
38 0     0 1   sub record_id { shift->as_hashref->{recordId} }
39 0     0 1   sub sensitivity { shift->as_hashref->{sensitivity} }
40 0     0 1   sub source { shift->as_hashref->{source} }
41 0     0 1   sub source_id { shift->as_hashref->{sourceId} }
42 0     0 1   sub system_description { shift->as_hashref->{systemDescription} }
43              
44             sub ips {
45 0     0 1   my ($self) = @_;
46 0           my @ips;
47 0 0         push @ips, $self->ip1 if $self->ip1;
48 0 0         push @ips, $self->ip2 if $self->ip2;
49 0 0         push @ips, $self->ip3 if $self->ip3;
50 0 0         push @ips, $self->ip4 if $self->ip4;
51 0 0         push @ips, $self->ip5 if $self->ip5;
52 0           return @ips;
53             }
54              
55             my %PROTOCOL = (
56             1 => 'TCP',
57             2 => 'UDP',
58             3 => 'HTTP',
59             4 => 'DNS',
60             5 => 'SMTP',
61             6 => 'HTTPS',
62             );
63              
64 0     0 1   sub protocol { $PROTOCOL{shift->protocol_id} }
65              
66 0     0 0   sub create { shift->update(@_) }
67              
68             sub disable {
69 0     0 1   my ($self) = @_;
70 0           $self->update(
71             port => $self->port,
72             failover => 'false',
73             monitor => 'false',
74             sensitivity => $self->sensitivity,
75             );
76              
77 0           my $res = $self->request(GET => $self->path);
78 0           $self->response($res);
79             }
80              
81             sub update {
82 0     0 1   my ($self, %data) = @_;
83              
84 0           my %req;
85 0           for my $old (keys %data) {
86 0           my $new = lower_camel_case($old);
87 0           $req{$new} = $data{$old};
88             }
89              
90 0           $self->clear_as_hashref;
91 0           my $res = $self->request(PUT => $self->path, \%req);
92 0           $self->response($res);
93             }
94              
95              
96             1;
97              
98             __END__
99              
100             =pod
101              
102             =encoding UTF-8
103              
104             =head1 NAME
105              
106             WWW::DNSMadeEasy::Monitor - DNS Failover and System Monitoring configuration
107              
108             =head1 VERSION
109              
110             version 0.100
111              
112             =head1 METHODS
113              
114             =head2 disable()
115              
116             Disables dns failover and system monitoring.
117              
118             =head2 update(%data)
119              
120             =head2 response()
121              
122             Returns the response for this object
123              
124             =head2 as_hashref()
125              
126             Returns json response data as a hashref
127              
128             =head2 record()
129              
130             Returns a L<WWW::DNSMadeEasy::ManagedDomain::Record> object.
131              
132             =head2 ips()
133              
134             Returns a list of failover ips (ip1, ip2, ...).
135              
136             =head2 protocol()
137              
138             Returns the protocol being monitored.
139              
140             protocol_id protocol
141             1 => TCP
142             2 => UDP
143             3 => HTTP
144             4 => DNS
145             5 => SMTP
146             6 => HTTP
147              
148             =head2 auto_failover()
149              
150             =head2 contact_list_id()
151              
152             =head2 failover()
153              
154             =head2 http_file()
155              
156             =head2 http_fqdn()
157              
158             =head2 http_query_string()
159              
160             =head2 ip1()
161              
162             =head2 ip1_failed()
163              
164             =head2 ip2()
165              
166             =head2 ip2_failed()
167              
168             =head2 ip3()
169              
170             =head2 ip3_failed()
171              
172             =head2 ip4()
173              
174             =head2 ip4_failed()
175              
176             =head2 ip5()
177              
178             =head2 ip5_failed()
179              
180             =head2 max_emails()
181              
182             =head2 monitor()
183              
184             =head2 port()
185              
186             =head2 protocol_id()
187              
188             =head2 record_id()
189              
190             =head2 sensitivity()
191              
192             =head2 source()
193              
194             =head2 source_id()
195              
196             =head2 system_description()
197              
198             =head1 METHODS
199              
200             =head1 MONITOR ATTRIBUTES
201              
202             =head1 SUPPORT
203              
204             IRC
205              
206             Join #duckduckgo on irc.freenode.net and highlight Getty or /msg me.
207              
208             Repository
209              
210             http://github.com/Getty/p5-www-dnsmadeeasy
211             Pull request and additional contributors are welcome
212              
213             Issue Tracker
214              
215             http://github.com/Getty/p5-www-dnsmadeeasy/issues
216              
217             =for :stopwords cpan testmatrix url bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan
218              
219             =head1 SUPPORT
220              
221             =head2 Source Code
222              
223             The code is open to the world, and available for you to hack on. Please feel free to browse it and play
224             with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull
225             from your repository :)
226              
227             L<https://github.com/Getty/p5-www-dnsmadeeasy>
228              
229             git clone https://github.com/Getty/p5-www-dnsmadeeasy.git
230              
231             =head1 AUTHOR
232              
233             Torsten Raudssus <torsten@raudssus.de>
234              
235             =head1 COPYRIGHT AND LICENSE
236              
237             This software is copyright (c) 2012 by L<Torsten Raudssus|https://raudssus.de/>.
238              
239             This is free software; you can redistribute it and/or modify it under
240             the same terms as the Perl 5 programming language system itself.
241              
242             =cut