2011-01-22 Sancho Lerena <slerena@artica.es>
* pandora_agent.c: Uses pandora_types.h instead module_types.h. Now delete the XML after sent. * configure.in: Change version. * pandora_config.c: Read remote_config variable and other small changes. * pandora_util.c: New function to produce timestamp strings, now report timestamp in XML. * TODO: Small doc about design goals and pending things to implement. * pandora_type.h: Renamed file with contains all structs. * util/pandora_agent_installer: Specific installer for Busybox. * util/pandora_agent_daemon: Specific daemon launcher for Busybox. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@3763 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
a264a8d61a
commit
4172871ecf
|
@ -1,4 +1,23 @@
|
|||
2011-01-22 Sancho Lerena <slerena@artica.es>
|
||||
|
||||
* pandora_agent.c: Uses pandora_types.h instead module_types.h
|
||||
|
||||
* configure.in: Change version.
|
||||
|
||||
* pandora_config.c: Read remote_config variable and other small changes.
|
||||
|
||||
* pandora_util.c: New function to produce timestamp strings, now report
|
||||
timestamp in XML.
|
||||
|
||||
* TODO: Small doc about design goals and pending things to implement.
|
||||
|
||||
* pandora_type.h: Renamed file with contains all structs.
|
||||
|
||||
* util/pandora_agent_installer: Specific installer for Busybox.
|
||||
|
||||
* util/pandora_agent_daemon: Specific daemon launcher for Busybox.
|
||||
|
||||
2011-01-21 Sancho Lerena <slerena@artica.es>
|
||||
|
||||
* First version of Pandora FMS Embedded C agent :-)
|
||||
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
This file is used to describe what needs to be implemented and how:
|
||||
|
||||
Design for embedded agent
|
||||
-------------------------
|
||||
|
||||
1. Absolutely NO USE of big libraries (glib!) or even unnecessary small ones, like libpopt, because porting could be a problem (and crosscompiling!). Issues about dependencies and size are key factors in embedded system.
|
||||
|
||||
2. All memory management should be dynamic, just to have the smallest impact on system performance / resources. Forget to reserve big arrays instead using malloc() :-)
|
||||
|
||||
3. Disk usage / access should be minimal and I/O operations on disk shoud be configurable to let user choose a I/O media not critical (NAND disk devices should be avoided).
|
||||
|
||||
4. When we talk "embedded" devices we are assuming systems using embedded Linux with Busybox. This is the "easier" enviroment, but we could use any other enviroment in the future.
|
||||
|
||||
Todo
|
||||
----
|
||||
|
||||
1. Read a complete .conf file (remote mode, and other parameters (group, description...).
|
||||
|
||||
2. Read a complete module especification, using a linked list (yes, forget to do using a big array :-), and supporting the parsing of vales with blank spaces in lines (forget to use an external library). This includes normal modules AND plugin modules.
|
||||
|
||||
3. Implement the remote configuration mode.
|
||||
|
||||
4. Implement file collection operations
|
||||
|
||||
5. Implement post-condition rules (in order to actuate from the agent to a attached serial device, for example).
|
||||
|
||||
6. Implement a "native" module in Pandora Embedded agent to read from a given device (i.e /dev/ttyUSB0) with a given parameters, with a timeout.
|
||||
|
||||
7. Implement the full drone mode (needs to implement the tentacle server first).
|
||||
|
||||
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
AC_PREREQ(2.59)
|
||||
|
||||
m4_define([pandora_major_version], [1])
|
||||
m4_define([pandora_minor_version], [0])
|
||||
m4_define([pandora_major_version], [4])
|
||||
m4_define([pandora_minor_version], [dev])
|
||||
m4_define([pandora_micro_version], [0])
|
||||
m4_define([pandora_build_version], [])
|
||||
m4_define([pandora_version], m4_format('%s.%s.%s%s', pandora_major_version, pandora_minor_version, pandora_micro_version, pandora_build_version))
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#include <errno.h>
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
#include "module_type.h"
|
||||
#include "pandora_type.h"
|
||||
#include "pandora_util.h"
|
||||
#include "pandora_config.h"
|
||||
|
||||
|
@ -93,6 +93,11 @@ main(int argc, char **argv) {
|
|||
}
|
||||
|
||||
tentacle_copy (xml_filename, pandorasetup);
|
||||
|
||||
// Embedded agents Doesnt implement the "buffered" sending,
|
||||
// if it cannot send, just drop the file
|
||||
|
||||
unlink (xml_filename);
|
||||
pandora_free(xml_filename);
|
||||
sleep(pandorasetup->interval);
|
||||
}
|
||||
|
|
|
@ -13,14 +13,14 @@
|
|||
#incoming_dir /var/spool/pandora/data_in/
|
||||
|
||||
# log_file: Main logfile for pandora_agent log, usually dev/null
|
||||
#logfile /dev/null
|
||||
logfile /tmp/pandora_agent.log
|
||||
logfile /dev/null
|
||||
#logfile /tmp/pandora_agent.log
|
||||
|
||||
# server_ip: Server hostname or IP address
|
||||
server_ip 192.168.5.50
|
||||
|
||||
# debug mode: If enabled doesn't copy XML and abort after first execution
|
||||
debug 1
|
||||
debug 0
|
||||
|
||||
# temporal: Temporal path: use sdcard if available, for example or ram disk
|
||||
temporal /tmp
|
||||
|
@ -29,7 +29,7 @@ temporal /tmp
|
|||
interval 300
|
||||
|
||||
# Agent name: if not provided, takes the host name
|
||||
agent_name adama
|
||||
agent_name AT91SAM9261
|
||||
|
||||
# Autotime: If set to 1, pandora will ignore timestamp of XML generated by this agent
|
||||
autotime 1
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include "module_type.h"
|
||||
#include "pandora_type.h"
|
||||
#include "pandora_util.h"
|
||||
|
||||
#define MAXLEN 1024
|
||||
|
@ -89,6 +89,9 @@ parse_config (struct pandora_setup* pandorasetup, char *config_file)
|
|||
else if (strcmp(name, "autotime")==0){
|
||||
pandorasetup->autotime = atoi(value);
|
||||
}
|
||||
else if (strcmp(name, "remote_config")==0){
|
||||
pandorasetup->remote_config = atoi(value);
|
||||
}
|
||||
else if (strcmp(name, "server_port")==0){
|
||||
pandorasetup->server_port = atoi(value);
|
||||
}
|
||||
|
|
6
pandora_agents/embedded/module_type.h → pandora_agents/embedded/pandora_type.h
Executable file → Normal file
6
pandora_agents/embedded/module_type.h → pandora_agents/embedded/pandora_type.h
Executable file → Normal file
|
@ -11,10 +11,6 @@
|
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// (TODO) Que coño es esto ??
|
||||
#define MOD_FILE 1
|
||||
#define MOD_ITEM 2
|
||||
|
||||
// Structs for Pandora Agent
|
||||
|
||||
struct pandora_agent {
|
||||
|
@ -46,7 +42,7 @@ struct pandora_setup {
|
|||
char *server_ip;
|
||||
char *temporal;
|
||||
int server_port;
|
||||
|
||||
int remote_config;
|
||||
char *sancho_test;
|
||||
};
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
#include "module_type.h"
|
||||
#include "pandora_type.h"
|
||||
#include "pandora_util.h"
|
||||
|
||||
|
||||
|
@ -31,6 +31,21 @@ pandora_free (void *pointer){
|
|||
}
|
||||
}
|
||||
|
||||
char *
|
||||
return_time (char *formatstring) {
|
||||
|
||||
char buffer[256];
|
||||
char *output;
|
||||
time_t curtime;
|
||||
struct tm *loctime;
|
||||
|
||||
curtime = time (NULL);
|
||||
loctime = localtime (&curtime);
|
||||
strftime (buffer, 256, formatstring, loctime);
|
||||
asprintf (&output, buffer);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
int
|
||||
pandora_return_unixtime () {
|
||||
|
@ -139,19 +154,28 @@ char *
|
|||
pandora_write_xml_header (struct pandora_setup *pandorasetup) {
|
||||
|
||||
char *os_version;
|
||||
char *date;
|
||||
char *buffer;
|
||||
char *buffer2;
|
||||
char *buffer3;
|
||||
|
||||
os_version = trim(pandora_exec ("uname -m"));
|
||||
|
||||
if (pandorasetup->autotime == 1){
|
||||
asprintf (&date, "AUTO");
|
||||
} else {
|
||||
date = return_time("%Y/%m/%d %H:%M:%S");
|
||||
}
|
||||
|
||||
|
||||
asprintf (&buffer, "<?xml version='1.0' encoding='ISO-8859-1'?>\n");
|
||||
asprintf (&buffer2, "<agent_data os_name='embedded' os_version='%s' interval='%d' version='4.0dev' timestamp='AUTO' agent_name='%s' >\n", os_version, pandorasetup->interval, pandorasetup->agent_name);
|
||||
asprintf (&buffer2, "<agent_data os_name='embedded' os_version='%s' interval='%d' version='4.0dev' timestamp='%s' agent_name='%s' >\n", os_version, pandorasetup->interval, date, pandorasetup->agent_name);
|
||||
asprintf (&buffer3, "%s%s",buffer, buffer2);
|
||||
|
||||
pandora_free (os_version);
|
||||
pandora_free (buffer2);
|
||||
pandora_free (buffer);
|
||||
pandora_free (date);
|
||||
return buffer3;
|
||||
}
|
||||
|
||||
|
@ -217,7 +241,6 @@ pandora_write_xml_disk (struct pandora_setup *pandorasetup){
|
|||
|
||||
fclose (pandora_xml);
|
||||
|
||||
|
||||
pandora_free (header);
|
||||
pandora_free (footer);
|
||||
return (filename);
|
||||
|
|
|
@ -21,3 +21,6 @@ pandora_free (void *pointer);
|
|||
int
|
||||
isdatafile (char *filename);
|
||||
|
||||
|
||||
char *
|
||||
return_time (char *formatstring);
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Pandora FMS Embedded Agent, startup script
|
||||
# Copyright (c) 2011 Artica ST, <info@artica.es>
|
||||
# Tested on Busybox 1.13
|
||||
# v4.0 Build 110122
|
||||
# http://www.pandorafms.com
|
||||
|
||||
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin
|
||||
PANDORA_PATH=/etc/pandora/pandora_agent.conf
|
||||
DAEMON=/usr/bin/pandora_agent
|
||||
LOGFILE=/dev/null
|
||||
|
||||
# This function replace pidof
|
||||
# not working in the same way in different linux distros
|
||||
|
||||
pidof_pandora() {
|
||||
COLUMNS=250
|
||||
PANDORA_PID=`ps | grep $DAEMON | grep -v grep | head -1 | awk '{ print $1 }'`
|
||||
echo $PANDORA_PID
|
||||
}
|
||||
|
||||
if [ ! -f $DAEMON ]
|
||||
then
|
||||
echo "Pandora FMS Agent not found at $DAEMON, please check setup"
|
||||
exit
|
||||
fi
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
PANDORA_PID=`pidof_pandora`
|
||||
if [ ! -z "$PANDORA_PID" ]
|
||||
then
|
||||
echo "Pandora FMS Agent is currently running on this machine with PID $PANDORA_PID"
|
||||
echo "Cannot launch again. Aborting."
|
||||
exit 1
|
||||
fi
|
||||
nohup $DAEMON $PANDORA_PATH 2> $LOGFILE &
|
||||
sleep 1
|
||||
PANDORA_PID=`pidof_pandora`
|
||||
echo "Pandora FMS Agent is now running with PID $PANDORA_PID"
|
||||
;;
|
||||
|
||||
stop)
|
||||
PANDORA_PID=`pidof_pandora`
|
||||
if [ -z "$PANDORA_PID" ]
|
||||
then
|
||||
echo "Pandora FMS Agent is not running, cannot stop it. Aborting now..."
|
||||
exit 1
|
||||
else
|
||||
echo "Stopping Pandora FMS Agent."
|
||||
kill $PANDORA_PID > /dev/null 2>&1
|
||||
fi
|
||||
;;
|
||||
|
||||
status)
|
||||
PANDORA_PID=`pidof_pandora`
|
||||
if [ -z "$PANDORA_PID" ]
|
||||
then
|
||||
echo "Pandora FMS Agent is not running."
|
||||
else
|
||||
echo "Pandora FMS Agent is running with PID $PANDORA_PID."
|
||||
fi
|
||||
exit 0
|
||||
;;
|
||||
|
||||
force-reload|restart)
|
||||
$0 stop
|
||||
sleep 2
|
||||
$0 start
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Usage: /etc/init.d/pandora_agent_daemon {start|stop|restart|status|force-reload}"
|
||||
exit 1
|
||||
esac
|
||||
|
|
@ -0,0 +1,110 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Pandora FMS Embedded Agent Installer (c) 2011 Artica ST
|
||||
# Embedded Version (generic), for Busybox enviroments only
|
||||
# Please see http://www.pandorafms.org
|
||||
# v4.0 Build 110121
|
||||
# This code is licensed under GPL 2.0 license.
|
||||
# **********************************************************************
|
||||
|
||||
PI_VERSION=4.0
|
||||
PANDORA_BIN=/usr/bin/pandora_agent
|
||||
PANDORA_TEMP=/tmp
|
||||
PANDORA_CFG=/etc/pandora
|
||||
PANDORA_LOG=/dev/null
|
||||
PANDORA_STARTUP=/etc/init.d/pandora_agent_daemon
|
||||
TENTACLE=/usr/bin/tentacle_client
|
||||
PANDORA_CFG_FILE=/etc/pandora/pandora_agent.conf
|
||||
|
||||
FORCE=0
|
||||
LOG_TIMESTAMP=`date +"%Y/%m/%d %H:%M:%S"`
|
||||
|
||||
MODE=$1
|
||||
|
||||
if [ ! -f "pandora_agent" ]
|
||||
then
|
||||
echo " "
|
||||
echo "You need to place pandora_agent file on main distribution directory before install"
|
||||
echo " "
|
||||
exit 1
|
||||
fi
|
||||
|
||||
get_distro () {
|
||||
echo ""
|
||||
}
|
||||
|
||||
uninstall () {
|
||||
DISTRO=`get_distro`
|
||||
echo "Removing Pandora FMS Agent..."
|
||||
rm -Rf $PANDORA_BIN
|
||||
rm -Rf $PANDORA_CFG_FILE
|
||||
rm -Rf $PANDORA_STARTUP
|
||||
rm -Rf $TENTACLE
|
||||
echo "Done"
|
||||
}
|
||||
|
||||
install () {
|
||||
DISTRO=`get_distro`
|
||||
|
||||
# Create directories
|
||||
mkdir $PANDORA_CFG 2> /dev/null
|
||||
|
||||
# Copying agent and securing it
|
||||
echo "Copying Pandora FMS Agent to $PANDORA_BIN..."
|
||||
cp pandora_agent $PANDORA_BIN
|
||||
chmod 700 $PANDORA_BIN
|
||||
|
||||
echo "Copying Pandora FMS Agent daemon to /etc/init.d"
|
||||
cp pandora_agent_daemon /etc/init.d
|
||||
|
||||
echo "Copying Pandora FMS Agent configuration file to /etc/pandora_agent.conf..."
|
||||
if [ -e /etc/pandora/pandora_agent.conf ]
|
||||
then
|
||||
cat /etc/pandora/pandora_agent.conf > /etc/pandora/pandora_agent.conf.old
|
||||
echo "Backing up old configuration file to /etc/pandora_agent.conf.old"
|
||||
fi
|
||||
|
||||
cp pandora_agent.conf /etc/pandora/pandora_agent.conf
|
||||
chmod 600 /etc/pandora/pandora_agent.conf
|
||||
|
||||
echo "Copying tentacle client to $TENTACLE"
|
||||
cp tentacle_client $TENTACLE
|
||||
|
||||
echo "NOTICE: You need to run the start-up script manually at /etc/init.d/pandora_agent_daemon";
|
||||
|
||||
chown -R root:root $PANDORA_BIN
|
||||
|
||||
echo "NOTICE: You need to setup your /etc/pandora_agent.conf config file"
|
||||
echo " "
|
||||
echo "Done"
|
||||
|
||||
}
|
||||
|
||||
help () {
|
||||
echo " --install To install Pandora FMS Agent on this system"
|
||||
echo " --uninstall To uninstall and remove Pandora FMS Agent on this System"
|
||||
echo " "
|
||||
}
|
||||
|
||||
# Script banner at start
|
||||
echo " "
|
||||
echo "Pandora FMS Agent Installer $PI_VERSION (c) 2008-2011 ArticaST"
|
||||
echo "This program is licensed under GPL2 Terms. http://pandorafms.com"
|
||||
echo " "
|
||||
|
||||
case "$MODE" in
|
||||
|
||||
'--install')
|
||||
install
|
||||
exit
|
||||
;;
|
||||
|
||||
'--uninstall')
|
||||
uninstall
|
||||
exit
|
||||
;;
|
||||
|
||||
*)
|
||||
help
|
||||
esac
|
||||
|
Loading…
Reference in New Issue