| 1 | package ETLp::Plugin::Iterative::OS; | ||
| 2 | |||
| 3 | use MooseX::Declare; | ||
| 4 | |||
| 5 | =head1 NAME | ||
| 6 | |||
| 7 | ETLp::Plugin::Iterative::OS - Plugin for calling the Operating System | ||
| 8 | |||
| 9 | =head1 METHODS | ||
| 10 | |||
| 11 | =head2 type | ||
| 12 | |||
| 13 | Registers the plugin type. | ||
| 14 | |||
| 15 | =head2 run | ||
| 16 | |||
| 17 | Executes the supplied Command. | ||
| 18 | |||
| 19 | =head3 parameters | ||
| 20 | |||
| 21 | * none | ||
| 22 | |||
| 23 | =head3 returns | ||
| 24 | |||
| 25 | * void | ||
| 26 | |||
| 27 | =head1 ITEM | ||
| 28 | |||
| 29 | The item attribute hashref contains specific configuration information | ||
| 30 | for ETLp::Plugin::Serial::OS | ||
| 31 | |||
| 32 | =head2 command | ||
| 33 | |||
| 34 | The operating system command being run | ||
| 35 | |||
| 36 | =head2 timeout | ||
| 37 | |||
| 38 | This is an optional parameter that specifies when the command execution | ||
| 39 | should abort (in seconds). | ||
| 40 | |||
| 41 | =cut | ||
| 42 | |||
| 43 | class ETLp::Plugin::Serial::OS extends ETLp::Plugin { | ||
| 44 | use Data::Dumper; | ||
| 45 | |||
| 46 | sub type { | ||
| 47 | return 'os'; | ||
| 48 | } | ||
| 49 | |||
| 50 | method run { | ||
| 51 | my $item = $self->item; | ||
| 52 | my $command = $item->{command}; | ||
| 53 | my $timeout = $item->{timeout} || 20; | ||
| 54 | |||
| 55 | $self->logger->debug(Dumper($self->config)); | ||
| 56 | |||
| 57 | my $message; | ||
| 58 | |||
| 59 | $self->logger->debug("Raw command:\n$command"); | ||
| 60 | $self->logger->debug("Timeout:\n$timeout"); | ||
| 61 | |||
| 62 | my $audit_item = $self->audit->item; | ||
| 63 | |||
| 64 | if ($item->{hide_command}) { | ||
| 65 | $message = $self->original_item->{command}; | ||
| 66 | } else { | ||
| 67 | $message = $command; | ||
| 68 | } | ||
| 69 | |||
| 70 | $audit_item->update_message($message); | ||
| 71 | |||
| 72 | my $cmd = ETLp::Utility::Command->new(time_out => $timeout); | ||
| 73 | |||
| 74 | my ($output, $retcode) = $cmd->run($command); | ||
| 75 | |||
| 76 | if ($retcode || $cmd->errstr) { | ||
| 77 | $self->logger->error("OS execution error:\n" . $cmd->errstr); | ||
| 78 | ETLpException->throw(error => "Error running:\n$message:\n" . | ||
| 79 | "$output\n". $cmd->errstr); | ||
| 80 | } | ||
| 81 | |||
| 82 | $audit_item->update_message($message . "\n" . $output); | ||
| 83 | } | ||
| 84 | } | ||
| 85 | |||
| 86 | =head1 LICENSE AND COPYRIGHT | ||
| 87 | |||
| 88 | Copyright 2010 Redbone Systems Ltd | ||
| 89 | |||
| 90 | This program is free software; you can redistribute it and/or modify it | ||
| 91 | under the terms of either: the GNU General Public License as published | ||
| 92 | by the Free Software Foundation; or the Artistic License. | ||
| 93 | |||
| 94 | The terms are in the LICENSE file that accompanies this application |