Skip to content

Commit

Permalink
allow methods selection
Browse files Browse the repository at this point in the history
  • Loading branch information
guillomovitch committed Oct 7, 2012
1 parent 949570e commit e548847
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
14 changes: 9 additions & 5 deletions fusioninventory-wakeonlan
Expand Up @@ -17,6 +17,7 @@ my $options = {};
GetOptions(
$options,
'mac=s',
'methods=s',
'debug+',
'help',
'version',
Expand Down Expand Up @@ -50,7 +51,9 @@ $task->{options} = {
],
};

$task->run();
my %params = $options->{methods} ?
(methods => [ split(/,/, $options->{methods}) ]) : ();
$task->run(%params);

__END__
Expand All @@ -63,10 +66,11 @@ fusioninventory-wakeonlan - Standalone wake-on-lan
fusioninventory-wakeonlan [options]
Options:
--mac=MAC target mac address
--debug debug output (execution traces)
-h --help print this message and exit
--version print the task version and exit
--mac=MAC target mac address
--methods=METHODS methods to use
--debug debug output (execution traces)
-h --help print this message and exit
--version print the task version and exit
=head1 DESCRIPTION
Expand Down
27 changes: 12 additions & 15 deletions lib/FusionInventory/Agent/Task/WakeOnLan.pm
Expand Up @@ -52,21 +52,18 @@ sub run {
my $target = $options->{PARAM}->[0]->{MAC};
$target =~ s/://g;

eval {
$self->_send_magic_packet_ethernet($target);
};
return unless $EVAL_ERROR;
$self->{logger}->error(
"Impossible to use ethernet magic packet: $EVAL_ERROR"
);

eval {
$self->_send_magic_packet_udp($target);
};
return unless $EVAL_ERROR;
$self->{logger}->error(
"Impossible to use UDP magic packet: $EVAL_ERROR"
);
my @methods = $params{methods} ? @{$params{methods}} : qw/ethernet udp/;

foreach my $method (@methods) {
eval {
my $function = '_send_magic_packet_' . $method;
$self->$function($target);
};
return unless $EVAL_ERROR;
$self->{logger}->error(
"Impossible to use $method magic packet: $EVAL_ERROR"
);
}

# For Windows, I don't know, just test
# See http://msdn.microsoft.com/en-us/library/ms740548(VS.85).aspx
Expand Down

0 comments on commit e548847

Please sign in to comment.