From bcf966b4515adc6d591bfdd8f415738e1a0ed10a Mon Sep 17 00:00:00 2001 From: slerena Date: Tue, 16 Sep 2008 15:19:14 +0000 Subject: [PATCH] 2008-09-16 Sancho Lerena * 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 --- pandora_server/ChangeLog | 7 + .../util/plugin/ssh-exec_pandoraplugin.pl | 134 ------------------ .../util/plugin/ssh_pandoraplugin.sh | 7 + 3 files changed, 14 insertions(+), 134 deletions(-) delete mode 100755 pandora_server/util/plugin/ssh-exec_pandoraplugin.pl create mode 100755 pandora_server/util/plugin/ssh_pandoraplugin.sh diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index 2ebcdab418..bfae754e31 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,10 @@ +2008-09-16 Sancho Lerena + + * 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 * bin/pandora_server: Use data timestamp when available (instead of diff --git a/pandora_server/util/plugin/ssh-exec_pandoraplugin.pl b/pandora_server/util/plugin/ssh-exec_pandoraplugin.pl deleted file mode 100755 index d4e2083058..0000000000 --- a/pandora_server/util/plugin/ssh-exec_pandoraplugin.pl +++ /dev/null @@ -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 \n\t -u \n\t -w \n\t -p \n\t -c \n\t -t \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; - diff --git a/pandora_server/util/plugin/ssh_pandoraplugin.sh b/pandora_server/util/plugin/ssh_pandoraplugin.sh new file mode 100755 index 0000000000..8b33aa1f11 --- /dev/null +++ b/pandora_server/util/plugin/ssh_pandoraplugin.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +HOST=$2 +USER=$4 +COMMAND=$5 + +ssh $USER@$HOST $COMMAND