/monitoring/NOCpulsePlugins/Windows/RemoteProgram.pm

https://github.com/colloquium/spacewalk · Perl · 36 lines · 20 code · 14 blank · 2 comment · 2 complexity · c8a874e486c19560cdbf17f61b9de682 MD5 · raw file

  1. package Windows::RemoteProgram;
  2. use strict;
  3. sub run {
  4. my %args = @_;
  5. my $result = $args{result};
  6. my $command = run_command(%args);
  7. #need to limit message size we send to notif system to ~1024 bytes
  8. my $output_string = substr($command->results, 0, 1024);
  9. $result->item_ok('Output', '"' . $output_string . '"') if $command->results;
  10. $result->item_critical('Error', '"' . $command->errors . '"') if $command->errors;
  11. }
  12. # Runs the command, assigns the status, and returns the WindowsCommand object.
  13. sub run_command {
  14. my %args = @_;
  15. my $result = $args{result};
  16. my %params = %{$args{params}};
  17. my $command = $args{data_source_factory}->windows_command(%params);
  18. $command->die_on_failure(0);
  19. $command->execute("run " . $params{command});
  20. return $command;
  21. }
  22. 1;