2008-09-16 Sancho Lerena <slerena@artica.es>
* util/plugin/ssh_pandoraplugin.sh: New remote SSH exec plugin. * util/plugin/ssh-exec_pandoraplugin.pl: Deleted old one because it has A LOT of problematic dependencies. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1096 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
868ac71def
commit
bcf966b451
|
@ -1,3 +1,10 @@
|
|||
2008-09-16 Sancho Lerena <slerena@artica.es>
|
||||
|
||||
* util/plugin/ssh_pandoraplugin.sh: New remote SSH exec plugin.
|
||||
|
||||
* util/plugin/ssh-exec_pandoraplugin.pl: Deleted old one because
|
||||
it has A LOT of problematic dependencies.
|
||||
|
||||
2008-09-15 Ramon Novoa <rnovoa@artica.es>
|
||||
|
||||
* bin/pandora_server: Use data timestamp when available (instead of
|
||||
|
|
|
@ -1,134 +0,0 @@
|
|||
#!/usr/bin/perl
|
||||
##################################################################################
|
||||
# OpenVPN Plugin for Pandora FMS 2.0
|
||||
# (c) Sancho Lerena 2008, slerena@gmail.com
|
||||
# This is the first plugin for Pandora FMS 2.0 plugin server
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; version 2
|
||||
# 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, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
##################################################################################
|
||||
|
||||
my $cfg_remote_host = "";
|
||||
my $cfg_remote_port = "22";
|
||||
my $cfg_password = "";
|
||||
my $cfg_user = "";
|
||||
my $cfg_command = "";
|
||||
my $cfg_timeout = 10;
|
||||
my $cfg_quiet = 0;
|
||||
|
||||
use Net::SSH::Perl;
|
||||
use Getopt::Std;
|
||||
use strict;
|
||||
|
||||
# ------------------------------------------------------------------------------------------
|
||||
# This function show a brief doc.
|
||||
# ------------------------------------------------------------------------------------------
|
||||
sub help {
|
||||
print "SSH-Exec Plugin for Pandora FMS 2.0, (c) Sancho Lerena 2008 \n";
|
||||
print "Syntax: \n\n";
|
||||
print "\t -a <host>\n\t -u <user>\n\t -w <pass>\n\t -p <port>\n\t -c <command>\n\t -t <timeout>\n\t -q\n";
|
||||
print "\n";
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------------------
|
||||
# Print an error and exit the program.
|
||||
# ------------------------------------------------------------------------------------------
|
||||
sub error {
|
||||
if ($cfg_quiet == 0) {
|
||||
print (STDERR "[err] $_[0]\n");
|
||||
}
|
||||
exit 1;
|
||||
}
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------------------
|
||||
# Read configuration from commandline parameters
|
||||
# ------------------------------------------------------------------------------------------
|
||||
sub config {
|
||||
my %opts;
|
||||
my $tmp;
|
||||
|
||||
# Get options
|
||||
if (getopts ('u:c:a:w:p:t:hq', \%opts) == 0 || defined ($opts{'h'})) {
|
||||
help ();
|
||||
exit 1;
|
||||
}
|
||||
|
||||
# Address
|
||||
if (defined ($opts{'a'})) {
|
||||
$cfg_remote_host = $opts{'a'};
|
||||
if ($cfg_remote_host !~ /^[a-zA-Z\.]+$/ && ($cfg_remote_host !~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/
|
||||
|| $1 < 0 || $1 > 255 || $2 < 0 || $2 > 255
|
||||
|| $3 < 0 || $3 > 255 || $4 < 0 || $4 > 255)) {
|
||||
error ("Address $cfg_remote_host is not valid.");
|
||||
}
|
||||
}
|
||||
|
||||
# Password
|
||||
if (defined ($opts{'w'})) {
|
||||
$cfg_password = $opts{'w'};
|
||||
}
|
||||
|
||||
# Command
|
||||
if (defined ($opts{'c'})) {
|
||||
$cfg_command = $opts{'c'};
|
||||
}
|
||||
|
||||
# User
|
||||
if (defined ($opts{'u'})) {
|
||||
$cfg_user = $opts{'u'};
|
||||
}
|
||||
|
||||
# Timeout
|
||||
if (defined ($opts{'t'})) {
|
||||
$cfg_timeout = $opts{'t'};
|
||||
}
|
||||
|
||||
# Port
|
||||
if (defined ($opts{'p'})) {
|
||||
$cfg_remote_port = $opts{'p'};
|
||||
if (($cfg_remote_port > 65550) || ($cfg_remote_port < 1)){
|
||||
error ("Port $cfg_remote_port is not valid.");
|
||||
}
|
||||
}
|
||||
|
||||
# Quiet mode
|
||||
if (defined ($opts{'q'})) {
|
||||
$cfg_quiet = 1;
|
||||
}
|
||||
|
||||
if (($cfg_remote_host eq "") || ($cfg_remote_port eq "")){
|
||||
error ("You need to define remote host and remote port to use this plugin");
|
||||
}
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------------------
|
||||
# This function exec a remote command using SSH
|
||||
# ------------------------------------------------------------------------------------------
|
||||
sub ssh_exec {
|
||||
my $out;
|
||||
my $err;
|
||||
my $exit;
|
||||
my $ssh = Net::SSH::Perl->new($cfg_remote_host, options => [ "Port $cfg_remote_port",
|
||||
"BatchMode yes" ]);
|
||||
$ssh->login($cfg_user, $cfg_password);
|
||||
($out, $err, $exit) = $ssh->cmd($cfg_command);
|
||||
return $out;
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------------------
|
||||
# Main program
|
||||
# ------------------------------------------------------------------------------------------
|
||||
|
||||
config();
|
||||
print ssh_exec();
|
||||
exit;
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
#!/bin/bash
|
||||
|
||||
HOST=$2
|
||||
USER=$4
|
||||
COMMAND=$5
|
||||
|
||||
ssh $USER@$HOST $COMMAND
|
Loading…
Reference in New Issue