2011-01-22 04:53:56 +01:00
|
|
|
|
// Pandora FMS Embedded Agent
|
|
|
|
|
// (c) Artica Soluciones Tecnol<6F>gicas S.L 2011
|
|
|
|
|
// (c) Sancho Lerena <slerena@artica.es>
|
|
|
|
|
|
|
|
|
|
// 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; either 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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <signal.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <dirent.h>
|
|
|
|
|
#include <unistd.h>
|
2011-01-22 21:29:06 +01:00
|
|
|
|
#include "pandora_type.h"
|
2011-01-22 04:53:56 +01:00
|
|
|
|
#include "pandora_util.h"
|
|
|
|
|
#include "pandora_config.h"
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
main(int argc, char **argv) {
|
2011-02-03 18:25:38 +01:00
|
|
|
|
DIR *pDIR=NULL;
|
|
|
|
|
struct dirent *pDirEnt=NULL;
|
|
|
|
|
struct pandora_setup *pandorasetup=NULL;
|
|
|
|
|
struct pandora_module *list=NULL;
|
|
|
|
|
char *config_file=NULL;
|
|
|
|
|
char *fullpath=NULL;
|
|
|
|
|
char *buffer=NULL;
|
|
|
|
|
long int id_audit;
|
|
|
|
|
char c;
|
|
|
|
|
char *xml_filename=NULL;
|
2011-01-22 04:53:56 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printf ("Pandora FMS Embedded Agent v%s (c) 2011 http://pandorafms.org\n", VERSION);
|
|
|
|
|
|
|
|
|
|
config_file = NULL;
|
2011-02-03 18:25:38 +01:00
|
|
|
|
list=NULL;
|
|
|
|
|
|
|
|
|
|
if (argc < 2 || argc > 3){
|
2011-01-22 04:53:56 +01:00
|
|
|
|
printf ("Syntax is:\n\n pandora_agent <path_to_pandora_agent.conf> \n\n");
|
|
|
|
|
exit (0);
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-03 18:25:38 +01:00
|
|
|
|
char *cmd = *argv++;
|
2011-01-22 04:53:56 +01:00
|
|
|
|
config_file = *argv++;
|
|
|
|
|
|
|
|
|
|
if (config_file == NULL) {
|
|
|
|
|
printf ("Cannot load configuration file. Exitting \n");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pandorasetup = malloc(sizeof(struct pandora_setup));
|
2011-02-03 18:25:38 +01:00
|
|
|
|
pandorasetup->logfile=NULL;
|
|
|
|
|
pandorasetup->agent_name=NULL;
|
|
|
|
|
pandorasetup->server_ip=NULL;
|
|
|
|
|
pandorasetup->temporal=NULL;
|
|
|
|
|
pandorasetup->sancho_test=NULL;
|
2011-01-22 04:53:56 +01:00
|
|
|
|
|
|
|
|
|
// Initialize to default parameters
|
|
|
|
|
init_parameters (pandorasetup);
|
|
|
|
|
|
|
|
|
|
// Load config file using first parameter
|
2011-02-03 18:25:38 +01:00
|
|
|
|
parse_config (pandorasetup, &list, config_file);
|
2011-01-22 04:53:56 +01:00
|
|
|
|
|
|
|
|
|
asprintf (&buffer,"Starting %s v%s", PACKAGE_NAME, VERSION);
|
|
|
|
|
pandora_log (3, buffer, pandorasetup);
|
|
|
|
|
pandora_free (buffer);
|
|
|
|
|
|
|
|
|
|
asprintf (&buffer,"Agent name: %s", pandorasetup->agent_name);
|
|
|
|
|
pandora_log (3, buffer, pandorasetup);
|
|
|
|
|
pandora_free (buffer);
|
|
|
|
|
|
|
|
|
|
asprintf (&buffer,"Server IP: %s", pandorasetup->server_ip);
|
|
|
|
|
pandora_log (3, buffer, pandorasetup);
|
|
|
|
|
pandora_free (buffer);
|
|
|
|
|
|
|
|
|
|
asprintf (&buffer,"Temporal: %s", pandorasetup->temporal);
|
|
|
|
|
pandora_log (3, buffer, pandorasetup);
|
|
|
|
|
pandora_free (buffer);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (1){ // Main loop
|
2011-02-03 18:25:38 +01:00
|
|
|
|
xml_filename = pandora_write_xml_disk (pandorasetup, list);
|
2011-01-22 04:53:56 +01:00
|
|
|
|
if (pandorasetup->debug == 1){
|
|
|
|
|
printf ("Debug mode activated. Exiting now! \n");
|
|
|
|
|
exit (0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tentacle_copy (xml_filename, pandorasetup);
|
2011-01-22 21:29:06 +01:00
|
|
|
|
|
|
|
|
|
// Embedded agents Doesnt implement the "buffered" sending,
|
|
|
|
|
// if it cannot send, just drop the file
|
|
|
|
|
|
|
|
|
|
unlink (xml_filename);
|
2011-01-22 04:53:56 +01:00
|
|
|
|
pandora_free(xml_filename);
|
|
|
|
|
sleep(pandorasetup->interval);
|
|
|
|
|
}
|
|
|
|
|
return (0);
|
|
|
|
|
}
|