| 1 | package App::Standby; | ||||||||||
| 2 | 3 | $App::Standby::VERSION = '0.04'; | |||||||||
| 3 | 3 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 3 | $App::Standby::AUTHORITY = 'cpan:TEX'; | |||||||||
| 5 | } | ||||||||||
| 6 | # ABSTRACT: Managing on-call rotation and notification queues | ||||||||||
| 7 | |||||||||||
| 8 | 3 | ▶ | use 5.010_000; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 3 | ▶ | use mro 'c3'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 3 | ▶ | use feature ':5.10'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 3 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 3 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | # use IO::Handle; | ||||||||||
| 16 | # use autodie; | ||||||||||
| 17 | # use MooseX::Params::Validate; | ||||||||||
| 18 | # use Carp; | ||||||||||
| 19 | # use English qw( -no_match_vars ); | ||||||||||
| 20 | # use Try::Tiny; | ||||||||||
| 21 | |||||||||||
| 22 | 3 | ▶ | use Log::Tree; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 23 | |||||||||||
| 24 | # extends ... | ||||||||||
| 25 | # has ... | ||||||||||
| 26 | 3 | has 'dbh' => ( | |||||||||
| 27 | 'is' => 'rw', | ||||||||||
| 28 | 'isa' => 'App::Standby::DB', | ||||||||||
| 29 | 'required' => 1, | ||||||||||
| 30 | ); | ||||||||||
| 31 | |||||||||||
| 32 | 3 | has 'logger' => ( | |||||||||
| 33 | 'is' => 'rw', | ||||||||||
| 34 | 'isa' => 'Log::Tree', | ||||||||||
| 35 | 'lazy' => 1, | ||||||||||
| 36 | 'builder' => '_init_logger', | ||||||||||
| 37 | ); | ||||||||||
| 38 | |||||||||||
| 39 | # with ... | ||||||||||
| 40 | # initializers ... | ||||||||||
| 41 | 0 | ▶ | sub _init_logger { | ||||||||
|
Subroutine
_init_logger: not called CC=1 SCAR=6.9
| |||||||||||
| 42 | 0 | my $self = shift; | |||||||||
| 43 | |||||||||||
| 44 | 0 | my $Logger = Log::Tree::->new('standby-mgm'); | |||||||||
| 45 | |||||||||||
| 46 | 0 | return $Logger; | |||||||||
| 47 | } | ||||||||||
| 48 | |||||||||||
| 49 | # your code here ... | ||||||||||
| 50 | 0 | ▶ | sub _config_values { | ||||||||
|
Subroutine
_config_values: not called CC=3 SCAR=24.8
| |||||||||||
| 51 | 0 | my $self = shift; | |||||||||
| 52 | 0 | my $key = shift; | |||||||||
| 53 | 0 | my $group_id = shift; | |||||||||
| 54 | |||||||||||
| 55 | 0 | my @args = (); | |||||||||
| 56 | 0 | my $sql = 'SELECT `value` FROM config WHERE `key` = ?'; | |||||||||
| 57 | 0 | push(@args,$key); | |||||||||
| 58 | 0 | ▶ | if($group_id) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 59 | 0 | $sql .= ' AND group_id = ?'; | |||||||||
| 60 | 0 | push(@args,$group_id); | |||||||||
| 61 | } | ||||||||||
| 62 | 0 | my $sth = $self->dbh()->prepare($sql); | |||||||||
| 63 | 0 | $sth->execute(@args); | |||||||||
| 64 | |||||||||||
| 65 | 0 | my @values = (); | |||||||||
| 66 | |||||||||||
| 67 | 0 | ▶ | while(my $value = $sth->fetchrow_array()) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 68 | 0 | push(@values,$value); | |||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | 0 | $sth->finish(); | |||||||||
| 72 | |||||||||||
| 73 | 0 | return \@values; | |||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | 0 | ▶ | sub _load_class { | ||||||||
|
Subroutine
_load_class: not called CC=2 SCAR=17.9
| |||||||||||
| 77 | 0 | my $self = shift; | |||||||||
| 78 | 0 | my $classname = shift; | |||||||||
| 79 | |||||||||||
| 80 | # String eval is bad. Always. Except for require ;) | ||||||||||
| 81 | ## no critic (ProhibitStringyEval) | ||||||||||
| 82 | 0 | my $ok = eval "require $classname;"; | |||||||||
| 83 | ## use critic | ||||||||||
| 84 | 0 | ▶ | if ($@) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 85 | 0 | return $@; | |||||||||
| 86 | } else { | ||||||||||
| 87 | 0 | return $classname; | |||||||||
| 88 | } | ||||||||||
| 89 | } | ||||||||||
| 90 | |||||||||||
| 91 | |||||||||||
| 92 | 0 | ▶ | sub get_groups { | ||||||||
|
Subroutine
get_groups: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 93 | 0 | my $self = shift; | |||||||||
| 94 | |||||||||||
| 95 | 0 | my $sql = 'SELECT id,name FROM groups'; | |||||||||
| 96 | 0 | my $sth = $self->dbh()->prepare($sql); | |||||||||
| 97 | |||||||||||
| 98 | 0 | my %grps = (); | |||||||||
| 99 | 0 | $sth->execute(); | |||||||||
| 100 | 0 | ▶ | while(my ($id,$name) = $sth->fetchrow_array()) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 101 | 0 | $grps{$id} = $name; | |||||||||
| 102 | } | ||||||||||
| 103 | |||||||||||
| 104 | 0 | $sth->finish(); | |||||||||
| 105 | |||||||||||
| 106 | 0 | return \%grps; | |||||||||
| 107 | } | ||||||||||
| 108 | |||||||||||
| 109 | 3 | ▶ | no Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 110 | 3 | __PACKAGE__->meta->make_immutable; | |||||||||
| 111 | |||||||||||
| 112 | 3 | 1; | |||||||||
| 113 | |||||||||||
| 114 | __END__ | ||||||||||
| 115 | |||||||||||
| 116 | =pod | ||||||||||
| 117 | |||||||||||
| 118 | =encoding utf-8 | ||||||||||
| 119 | |||||||||||
| 120 | =head1 NAME | ||||||||||
| 121 | |||||||||||
| 122 | App::Standby - Managing on-call rotation and notification queues | ||||||||||
| 123 | |||||||||||
| 124 | =head1 DESCRIPTION | ||||||||||
| 125 | |||||||||||
| 126 | This distribution provides a small Plack webapp which helps with managing on-call rotations | ||||||||||
| 127 | and notification queues. It allows you to manage several different queues from | ||||||||||
| 128 | on place. It is easily extendible by plugins which can talk to virtually API | ||||||||||
| 129 | endpoint to update a queue or a contact. | ||||||||||
| 130 | |||||||||||
| 131 | Most organizations have at least one big monitoring system (like Nagios or Zabbix) and | ||||||||||
| 132 | at least one external service level monitoring and other means of notification, | ||||||||||
| 133 | If you don't want to pass around a shared on-call mobile you have to remember to update all | ||||||||||
| 134 | those services when the one on duty changes. This app will help you with that. | ||||||||||
| 135 | |||||||||||
| 136 | It allows you to manage several groups with their own queues and update each | ||||||||||
| 137 | groups external services with just one click. | ||||||||||
| 138 | |||||||||||
| 139 | =head1 METHODS | ||||||||||
| 140 | |||||||||||
| 141 | =head2 get_groups | ||||||||||
| 142 | |||||||||||
| 143 | Returns a list of all groups. | ||||||||||
| 144 | |||||||||||
| 145 | =head1 NAME | ||||||||||
| 146 | |||||||||||
| 147 | App::Standby - Managing on-call rotation and notification queues | ||||||||||
| 148 | |||||||||||
| 149 | =head1 SETUP | ||||||||||
| 150 | |||||||||||
| 151 | This app can be run as CGI or from within an PSGI runtime like Starman. | ||||||||||
| 152 | |||||||||||
| 153 | It needs not runtime configuration unless you want to change the path to the SQLite | ||||||||||
| 154 | database file. | ||||||||||
| 155 | |||||||||||
| 156 | You need to bootstrap the app by creating the first group like this: | ||||||||||
| 157 | |||||||||||
| 158 | standby-mgm.pl bootstrap -nRoadies -kbase | ||||||||||
| 159 | |||||||||||
| 160 | This will create the group named "Roadies" with the key "base". The key is a simple | ||||||||||
| 161 | shared key necessary to change any value for this group in the webinterface. This | ||||||||||
| 162 | is the most basic form of authorization, but has proven sufficient so far. Patches | ||||||||||
| 163 | for more extensive forms of authentication are welcome. | ||||||||||
| 164 | |||||||||||
| 165 | WARNING: Make sure the database file is owned by the user service the webinterface | ||||||||||
| 166 | and also accessible by the user execution your cronjobs, e.g. www-data. | ||||||||||
| 167 | |||||||||||
| 168 | chown -R www-data:www-data /var/lib/standby-mgm/ | ||||||||||
| 169 | |||||||||||
| 170 | =head1 CONFIGURATION | ||||||||||
| 171 | |||||||||||
| 172 | This section provides an example of a complete configuration using dummy values for names, | ||||||||||
| 173 | phone numbers, URLs and the like. | ||||||||||
| 174 | |||||||||||
| 175 | =head2 SERVICES | ||||||||||
| 176 | |||||||||||
| 177 | In order for this app to do anything there must be two things in the database: users and services. | ||||||||||
| 178 | This section will show you how to create the later. | ||||||||||
| 179 | |||||||||||
| 180 | First select services and open up the new service dialog. Enter a short name for this service. | ||||||||||
| 181 | Remember it must be all lowercase alphanumerics since it's going to be used as a prefix for the | ||||||||||
| 182 | configuration values later. The description can be anything. Select the appropriate class and | ||||||||||
| 183 | enter the group password you've dedfined when bootstrapping the service. | ||||||||||
| 184 | |||||||||||
| 185 | Choose class HTTP for a simple endpoint which just gets the whole ordered user list as a JSON | ||||||||||
| 186 | string. Chosse MS for a Monitoring::Spooler endpoint and Pingdom if you have an Pingdom account. | ||||||||||
| 187 | |||||||||||
| 188 | Add as many services as necessary. | ||||||||||
| 189 | |||||||||||
| 190 | Next select config from the menu and add new config items. For each service at least one. The | ||||||||||
| 191 | HTTP service need an endpoint, so if the HTTP service was called simple then the config item | ||||||||||
| 192 | for the endpoint must be called simple_endpoint and contain something like http://simple.domain/api/. | ||||||||||
| 193 | |||||||||||
| 194 | For any pingdom service there must be at least four config items. The necessary items are apikey, | ||||||||||
| 195 | username, password and contact_id. The last one may be given multiple times to update | ||||||||||
| 196 | multiple Pingdom contacts in one account. If your service is called pingdom the keys would be | ||||||||||
| 197 | called pingdom_apikey, pingdom_username, pingdom_password and pingdom_contact_id. | ||||||||||
| 198 | |||||||||||
| 199 | The MS service class needs an endpoint and a group id (name_group_id) which is used | ||||||||||
| 200 | to update the appropriate group in the MS DB. If you call your MS service "ms" then the necessary | ||||||||||
| 201 | keys would be called "ms_endpoint" with a value of e.g. "http://localhost/ms/?rm=update_queue" and | ||||||||||
| 202 | "ms_group_id" with a value of e.g. "1". | ||||||||||
| 203 | |||||||||||
| 204 | Have a look at the CPAN distribution Monitoring::Spooler for more documentation on MS. | ||||||||||
| 205 | |||||||||||
| 206 | =head2 CONTACTS | ||||||||||
| 207 | |||||||||||
| 208 | To be able to notify someone you must add some contacts. Since the whole point of this app | ||||||||||
| 209 | is to help with managing changing on call rotations you should create more than one contact. | ||||||||||
| 210 | |||||||||||
| 211 | Create at least two contacts. The name may be anything but you should know who it is refering to. | ||||||||||
| 212 | The cellphone number should be in normalized international format (+<countryprefix><areaprefix> | ||||||||||
| 213 | <extension>). Again, enter the group key to authenticate yourself. | ||||||||||
| 214 | |||||||||||
| 215 | After creation contacts are disabled and won't participate in any rotation, so be sure to enable | ||||||||||
| 216 | some users (usually all). | ||||||||||
| 217 | |||||||||||
| 218 | Some services may need additional configuration per users, so you can store additional config | ||||||||||
| 219 | under each user. | ||||||||||
| 220 | |||||||||||
| 221 | Now you need to change the notification order at least once to make sure all remote services | ||||||||||
| 222 | are updated. This happens only when the order is changed. | ||||||||||
| 223 | |||||||||||
| 224 | =head1 PLUGINS | ||||||||||
| 225 | |||||||||||
| 226 | Have a look at the examples directory for some example plugins. | ||||||||||
| 227 | |||||||||||
| 228 | =head1 DEBUGGING | ||||||||||
| 229 | |||||||||||
| 230 | If anything goes wrong have a look at the logfile. Depending on your configuration its either at | ||||||||||
| 231 | /var/log/standby-mgm.log or /tmp/standby-mgm.log. | ||||||||||
| 232 | |||||||||||
| 233 | =head1 AUTHOR | ||||||||||
| 234 | |||||||||||
| 235 | Dominik Schulz <dominik.schulz@gauner.org> | ||||||||||
| 236 | |||||||||||
| 237 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 238 | |||||||||||
| 239 | This software is copyright (c) 2012 by Dominik Schulz. | ||||||||||
| 240 | |||||||||||
| 241 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 242 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 243 | |||||||||||
| 244 | =cut | ||||||||||