summaryrefslogtreecommitdiffstats
path: root/mgaonline_agent.pl
blob: d7bae8e5e6dc1ae7e5d745c682893d0ddb9bd5f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/perl -w
################################################################################
# mgaonline_agent                                                              #
#                                                                              #
# Copyright (C) 2005-2010 Mandriva                                             #
#               2010-2015 Mageia                                               #
#                                                                              #
# Romain d'Alverny <rdalverny at mandriva dot com>                             #
#                                                                              #
# This program is free software; you can redistribute it and/or modify         #
# it under the terms of the GNU General Public License Version 2 as            #
# published by the Free Software Foundation.                                   #
#                                                                              #
# This program is distributed in the hope that it will be useful,              #
# but WITHOUT ANY WARRANTY; without even the implied warranty of               #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                #
# GNU General Public License for more details.                                 #
#                                                                              #
# You should have received a copy of the GNU General Public License            #
# along with this program; if not,  see <http://www.gnu.org/licenses/>.        #
################################################################################

# $Id$

use strict;
use POSIX;
use lib qw(/usr/lib/libDrakX /usr/lib/libDrakX/drakfirsttime);
use common;
use mgaonline;
use Switch;
use Data::Dumper;
use Error qw(:try);

# DNS service discovery
use Discover;

# logging
use Log::Agent;
require Log::Agent::Driver::File;  # logging made to file
logconfig(
    '-driver' => Log::Agent::Driver::File->make(
        '-prefix'  => $0,
        '-showpid' => 1,
        '-file'    => 'mgaonline.log',
    ),
    #-caller => [ -display => '($sub/$line)', -postfix => 1 ],
    '-priority' => [ '-display' => '[$priority]' ],
);

logsay "==================";
mgaonline::is_running('mgaonline_agent') and die "mgaonline_agent already running\n";
require_root_capability();

my %conf = mgaonline::get_configuration();
print Dumper(%conf);

! defined %conf and logwarn "no configuration set", exit 0;

logsay "checking for tasks";
print Dumper(%conf);
my $answer = mgaonline::soap_get_task($conf{HOST_ID}, $conf{HOST_KEY});

print Dumper($answer);

if ($answer->{code} == 0) {
	if ($answer->{data}{command} eq 'none') {
		logsay "nothing to do";
	}
	else {
		logsay "got something";
		mgaonline::run_and_return_task($answer->{data});
	}
	exit 1;
}
else {
	logwarn "something went wrong " . $answer->{message} . " (" . $answer->{code} . ")";
	exit 0;
}