1 |
#!/usr/bin/perl -w |
2 |
################################################################################ |
3 |
# mdvonline_agent # |
4 |
# # |
5 |
# Copyright (C) 2005 Mandriva # |
6 |
# # |
7 |
# Romain d'Alverny <rdalverny at mandriva dot com> # |
8 |
# # |
9 |
# This program is free software; you can redistribute it and/or modify # |
10 |
# it under the terms of the GNU General Public License Version 2 as # |
11 |
# published by the Free Software Foundation. # |
12 |
# # |
13 |
# This program is distributed in the hope that it will be useful, # |
14 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of # |
15 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # |
16 |
# GNU General Public License for more details. # |
17 |
# # |
18 |
# You should have received a copy of the GNU General Public License # |
19 |
# along with this program; if not, write to the Free Software # |
20 |
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # |
21 |
################################################################################ |
22 |
|
23 |
# $Id$ |
24 |
|
25 |
use strict; |
26 |
use POSIX; |
27 |
use lib qw(/usr/lib/libDrakX /usr/lib/libDrakX/drakfirsttime); |
28 |
use common; |
29 |
use mgaonline; |
30 |
use Switch; |
31 |
use Data::Dumper; |
32 |
use Error qw(:try); |
33 |
|
34 |
# DNS service discovery |
35 |
use Discover; |
36 |
|
37 |
# logging |
38 |
use Log::Agent; |
39 |
require Log::Agent::Driver::File; # logging made to file |
40 |
logconfig( |
41 |
'-driver' => Log::Agent::Driver::File->make( |
42 |
'-prefix' => $0, |
43 |
'-showpid' => 1, |
44 |
'-file' => 'mdvonline.log', |
45 |
), |
46 |
#-caller => [ -display => '($sub/$line)', -postfix => 1 ], |
47 |
'-priority' => [ '-display' => '[$priority]' ], |
48 |
); |
49 |
|
50 |
logsay "=================="; |
51 |
mgaonline::is_running('mdvonline_agent') and die "mdvonline_agent already running\n"; |
52 |
require_root_capability(); |
53 |
|
54 |
my %conf = mgaonline::get_configuration(); |
55 |
print Dumper(%conf); |
56 |
|
57 |
! defined %conf and logwarn "no configuration set", exit 0; |
58 |
|
59 |
logsay "checking for tasks"; |
60 |
print Dumper(%conf); |
61 |
my $answer = mgaonline::soap_get_task($conf{HOST_ID}, $conf{HOST_KEY}); |
62 |
|
63 |
print Dumper($answer); |
64 |
|
65 |
if ($answer->{code} == 0) { |
66 |
if ($answer->{data}{command} eq 'none') { |
67 |
logsay "nothing to do"; |
68 |
} |
69 |
else { |
70 |
logsay "got something"; |
71 |
mgaonline::run_and_return_task($answer->{data}); |
72 |
} |
73 |
exit 1; |
74 |
} |
75 |
else { |
76 |
logwarn "something went wrong " . $answer->{message} . " (" . $answer->{code} . ")"; |
77 |
exit 0; |
78 |
} |