2008-05-19 Ramon Novoa <rnovoa@artica.es>
* linux/pandora_agent_installer: Added plugin installation. * linux/plugins: Added to repository. Plugins directory. * linux/plugins/grep_log: Added to repository. Plugin to search log files for a matching pattern. * linux/pandora_agent: Added support for plugin execution. Removed support for pandora_user.conf. * linux/pandora_user.conf: Deleted from repository. Not used anymore. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@836 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
dc1d0f1a15
commit
be0f836dda
|
@ -1,3 +1,13 @@
|
|||
2008-05-19 Ramon Novoa <rnovoa@artica.es>
|
||||
|
||||
* linux/pandora_agent_installer: Added plugin installation.
|
||||
* linux/plugins: Added to repository. Plugins directory.
|
||||
* linux/plugins/grep_log: Added to repository. Plugin to search log
|
||||
files for a matching pattern.
|
||||
* linux/pandora_agent: Added support for plugin execution. Removed
|
||||
support for pandora_user.conf.
|
||||
* linux/pandora_user.conf: Deleted from repository. Not used anymore.
|
||||
|
||||
2008-04-09 Sancho lerena <slerena@gmail.com>
|
||||
|
||||
* README, AUTHORS, COPYING: Updated on all agents.
|
||||
|
|
|
@ -322,6 +322,19 @@ do
|
|||
EXECUTE=`expr \( $CONTADOR + 1 \) % $MODULEINTERVAL`
|
||||
fi
|
||||
|
||||
# Plugin execution
|
||||
if [ ! -z "`echo $a | grep '^module_plugin'`" ]
|
||||
then
|
||||
PLUGIN=`echo $a | cut -d" " -f2`
|
||||
PARAMS=`echo $a | cut -d" " -f3-`
|
||||
if [ -f $PANDORA_HOME/plugins/$PLUGIN ]
|
||||
then
|
||||
eval $PANDORA_HOME/plugins/$PLUGIN $PARAMS >> $DATA
|
||||
else
|
||||
echo "$PANDORA_HOME/plugins/$PLUGIN not found"
|
||||
fi
|
||||
fi
|
||||
|
||||
# If module ends, and execute for this module is enabled
|
||||
# then write
|
||||
|
||||
|
@ -343,11 +356,6 @@ do
|
|||
CONTADOR=0
|
||||
fi
|
||||
|
||||
# Call for user-defined script for data adquisition
|
||||
if [ -f "$PANDORA_HOME/pandora_user.conf" ]
|
||||
then
|
||||
/bin/bash $PANDORA_HOME/pandora_user.conf >> $DATA
|
||||
fi
|
||||
|
||||
# Checking MD5
|
||||
if [ "$CHECKSUM_MODE" == "1" ]
|
||||
|
|
|
@ -87,9 +87,11 @@ install () {
|
|||
cp pandora_agent.conf $PANDORA_HOME
|
||||
chmod 600 $PANDORA_HOME/pandora_agent.conf
|
||||
|
||||
echo "Copying Pandora FMS Agent user configuration file to $PANDORA_HOME/pandora_user.conf..."
|
||||
cp pandora_user.conf $PANDORA_HOME
|
||||
chmod 700 $PANDORA_HOME/pandora_user.conf
|
||||
echo "Copying Pandora FMS Agent plugins to $PANDORA_HOME/plugins..."
|
||||
cp -r plugins $PANDORA_HOME
|
||||
chmod -R 700 $PANDORA_HOME/plugins
|
||||
echo "Linking Pandora FMS Agent plugins directory to $PANDORA_CFG/plugins..."
|
||||
ln -s $PANDORA_HOME/plugins $PANDORA_CFG
|
||||
|
||||
echo "Linking Pandora FMS Agent configuration to $PANDORA_CFG/pandora_agent.conf..."
|
||||
ln -s $PANDORA_HOME/pandora_agent.conf $PANDORA_CFG
|
||||
|
|
|
@ -1,75 +0,0 @@
|
|||
# Pandora User-Defined adquisition script
|
||||
# This code is under GPL licence
|
||||
# This is the default user script file
|
||||
# If you're using this is because default config doest fit all your needs
|
||||
# You can use the following variables
|
||||
#
|
||||
# All STDOUT output will be written in final XML file sent to Pandora Server.
|
||||
#
|
||||
# Please refer documentatation for more example and a more depth usage instructions
|
||||
#
|
||||
|
||||
# ================================
|
||||
# Check for WEBPage content change
|
||||
# ================================
|
||||
|
||||
#MYMD5=`echo -e "GET / HTTP/1.0\n\n\n" | nc -w 30 www.artica.es 80 | grep -v "Date:" | md5sum | awk '{ print $1 }'`
|
||||
#VALIDMD5=e85c0b9018a22c1086c8e0179cd224b1
|
||||
#if [ "$MYMD5" != "$VALIDMD5" ]
|
||||
#then
|
||||
# MD5SUM=0
|
||||
#else
|
||||
# MD5SUM=1
|
||||
#fi
|
||||
#echo "<module>"
|
||||
#echo "<name>www.artica.es_WEBContenct</name>"
|
||||
#echo "<type>generic_proc</type>"
|
||||
#echo "<data>$MD5SUM</data>"
|
||||
#echo "</module>"
|
||||
|
||||
# MODULE END ========================
|
||||
|
||||
# ================================
|
||||
# Check for DNS Entry change
|
||||
# ================================
|
||||
|
||||
#HOSTNAME=arcadia.genterara.com
|
||||
#MAXHOPS=1
|
||||
#MAXHOPS2=`expr $MAXHOPS + 1`
|
||||
#SALIDA=`traceroute -n $HOSTNAME -w 5 -m $MAXHOPS2 2> /dev/null | awk '{ print $1 }' | tail -1`
|
||||
# if SALIDA != MAXHOPS, error (more than MAXHOPS hop, if this is our local IP, no more than MAXHOPS hop its needed
|
||||
#if [ "$SALIDA" == "$MAXHOPS" ]
|
||||
#then
|
||||
# DNS_STATUS=1
|
||||
#else
|
||||
# DNS_STATUS=0
|
||||
#fi
|
||||
#echo "<module>"
|
||||
#echo "<name>DNS_CHECK</name>"
|
||||
#echo "<type>generic_proc</type>"
|
||||
#echo "<data>$DNS_STATUS</data>"
|
||||
#echo "</module>"
|
||||
|
||||
# MODULE END ========================
|
||||
|
||||
|
||||
# ================================
|
||||
# Check for DNS Entry change
|
||||
# on local interface ppp0
|
||||
# ================================
|
||||
|
||||
# PLC_DNS=`dig @194.179.1.101 plc.genterara.com A +short | tail -1 `
|
||||
# PLC_LOCAL=`ifconfig ppp0 | head -2 | tail -1 | tr -s ":" " " | awk ' { print $3 } '`
|
||||
# if [ "$PLC_DNS" == "$PLC_LOCAL" ]
|
||||
# then
|
||||
# PLC_STATUS=1
|
||||
# else
|
||||
# PLC_STATUS=0
|
||||
# fi
|
||||
#
|
||||
# echo "<module>"
|
||||
# echo "<name>PLC_DNS_CHECK</name>"
|
||||
# echo "<type>generic_proc</type>"
|
||||
# echo "<data>$PLC_STATUS</data>"
|
||||
# echo "</module>"
|
||||
# MODULE END ========================
|
|
@ -0,0 +1,237 @@
|
|||
#!/usr/bin/perl
|
||||
###############################################################################
|
||||
#
|
||||
# Copyright (c) 2008 Ramon Novoa <rnovoa@artica.es>
|
||||
# Copyright (c) 2008 Artica Soluciones Tecnologicas S.L.
|
||||
#
|
||||
# grep_log Perl script to search log files for a matching pattern. The last
|
||||
# searched position is saved in an index file so that consecutive
|
||||
# runs do not return the same results. The log file inode number is
|
||||
# also saved to detect log rotation.
|
||||
#
|
||||
# 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 of the License.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
use strict;
|
||||
use File::Basename;
|
||||
|
||||
# Be verbose
|
||||
my $Verbose = 0;
|
||||
|
||||
# Index file storage directory, with a trailing '/'
|
||||
my $Idx_dir='/var/pandora/';
|
||||
|
||||
# Log file
|
||||
my $Log_file = '';
|
||||
|
||||
# Index file
|
||||
my $Idx_file = '';
|
||||
|
||||
# Log file position index
|
||||
my $Idx_pos = 0;
|
||||
|
||||
# Log file inode number
|
||||
my $Idx_ino = '';
|
||||
|
||||
# Regular expression to be matched
|
||||
my $Reg_exp = '';
|
||||
|
||||
###############################################################################
|
||||
# SUB error_msg
|
||||
# Print an error message and exit.
|
||||
###############################################################################
|
||||
sub error_msg ($) {
|
||||
my $err_msg = $_[0];
|
||||
|
||||
if (! -z $err_msg) {
|
||||
print(stderr "[error] $err_msg.\n");
|
||||
}
|
||||
|
||||
exit 1;
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
# SUB print_help
|
||||
# Print a help message.
|
||||
###############################################################################
|
||||
sub print_help () {
|
||||
print "Usage: $0 <log_file> <pattern>\n";
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
# SUB log_msg
|
||||
# Print a log message.
|
||||
###############################################################################
|
||||
sub log_msg ($) {
|
||||
my $log_msg = $_[0];
|
||||
|
||||
if (! -z $log_msg && $Verbose == 1) {
|
||||
print(stdout "[log] $log_msg.\n");
|
||||
}
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
# SUB load_idx
|
||||
# Load index file.
|
||||
###############################################################################
|
||||
sub load_idx () {
|
||||
my $line;
|
||||
my $current_ino;
|
||||
|
||||
log_msg("Loading index file $Idx_file");
|
||||
|
||||
open(IDXFILE, $Idx_file) || error_msg("Error opening file $Idx_file: " .
|
||||
$!);
|
||||
|
||||
# Read position and date
|
||||
$line = <IDXFILE>;
|
||||
($Idx_pos, $Idx_ino) = split(' ', $line);
|
||||
|
||||
close(IDXFILE);
|
||||
|
||||
# Reset the file index if the file has changed
|
||||
$current_ino = (stat($Log_file))[1];
|
||||
if ($current_ino != $Idx_ino) {
|
||||
log_msg("File changed, resetting index");
|
||||
|
||||
$Idx_pos = 0;
|
||||
$Idx_ino = $current_ino;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
# SUB save_idx
|
||||
# Save index file.
|
||||
###############################################################################
|
||||
sub save_idx () {
|
||||
|
||||
log_msg("Saving index file $Idx_file");
|
||||
|
||||
open(IDXFILE, "> $Idx_file") || error_msg("Error opening file $Idx_file: "
|
||||
. $!);
|
||||
print (IDXFILE $Idx_pos . " " . $Idx_ino);
|
||||
close(IDXFILE);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
# SUB create_idx
|
||||
# Create index file.
|
||||
###############################################################################
|
||||
sub create_idx () {
|
||||
my $first_line;
|
||||
|
||||
log_msg("Creating index file $Idx_file");
|
||||
|
||||
open(LOGFILE, $Log_file) || error_msg("Error opening file $Log_file: " .
|
||||
$!);
|
||||
|
||||
# Go to EOF and save the position
|
||||
seek(LOGFILE, 0, 2);
|
||||
$Idx_pos = tell(LOGFILE);
|
||||
|
||||
close(LOGFILE);
|
||||
|
||||
# Save the file inode number
|
||||
$Idx_ino = (stat($Log_file))[1];
|
||||
|
||||
# Save the index file
|
||||
save_idx();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
# SUB parse_log
|
||||
# Parse log file starting from position $Idx_pos.
|
||||
###############################################################################
|
||||
sub parse_log () {
|
||||
my $line;
|
||||
|
||||
log_msg("Parsing log file $Log_file");
|
||||
|
||||
# Open log file for reading
|
||||
open(LOGFILE, $Log_file) || error_msg("Error opening file $Log_file: " .
|
||||
$!);
|
||||
|
||||
# Go to starting position
|
||||
seek(LOGFILE, $Idx_pos, 0);
|
||||
|
||||
print (stdout "<module>\n");
|
||||
print (stdout "<name><![CDATA[" . basename($0) . "]]></name>\n");
|
||||
print (stdout "<type><![CDATA[generic_data_string]]></type>\n");
|
||||
print (stdout "<datalist>\n");
|
||||
|
||||
# Parse log file
|
||||
while ($line = <LOGFILE>) {
|
||||
if ($line =~ m/$Reg_exp/i) {
|
||||
# Remove the trailing '\n'
|
||||
chop($line);
|
||||
|
||||
print (stdout "<data><value><![CDATA[$line]]></value></data>\n");
|
||||
}
|
||||
}
|
||||
|
||||
print (stdout "</datalist>\n");
|
||||
print (stdout "</module>\n");
|
||||
|
||||
$Idx_pos = tell(LOGFILE);
|
||||
close(LOGFILE);
|
||||
|
||||
# Save the index file
|
||||
save_idx();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
###############################################################################
|
||||
## Main
|
||||
###############################################################################
|
||||
###############################################################################
|
||||
|
||||
# Check command line parameters
|
||||
if ($#ARGV != 1) {
|
||||
print_help();
|
||||
exit 1;
|
||||
}
|
||||
|
||||
$Log_file = $ARGV[0];
|
||||
$Reg_exp = $ARGV[1];
|
||||
|
||||
# Create index file storage directory
|
||||
if ( ! -d $Idx_dir) {
|
||||
mkdir($Idx_dir) || error_msg("Error creating directory $Idx_dir: "
|
||||
. $!);
|
||||
}
|
||||
|
||||
# Check that log file exists
|
||||
if (! -e $Log_file) {
|
||||
error_msg("File $Log_file does not exist");
|
||||
}
|
||||
|
||||
# Create index file if it does not exist
|
||||
$Idx_file=$Idx_dir . basename($Log_file) . ".idx";
|
||||
if (! -e $Idx_file) {
|
||||
create_idx();
|
||||
exit 0;
|
||||
}
|
||||
|
||||
# Load index file
|
||||
load_idx();
|
||||
|
||||
# Parse log file
|
||||
parse_log();
|
||||
|
||||
exit 0;
|
Loading…
Reference in New Issue