***********************
** FILE NAME : gcm_input.cpp
** SYSTEM NAME : Gnucomo - Gnu Computer Monitoring
-** VERSION NUMBER : $Revision: 1.1 $
+** VERSION NUMBER : $Revision: 1.2 $
**
** DESCRIPTION : Application to store client messages into the database
** The client message contains a log file from one of the
********************************
** ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
** CREATION DATE : Aug 29, 2002
-** LAST UPDATE : Sep 30, 2002
+** LAST UPDATE : Nov 04, 2002
** MODIFICATIONS :
**************************************************************************/
/*****************************
$Log: gcm_input.cpp,v $
- Revision 1.1 2002-10-05 10:25:49 arjen
+ Revision 1.2 2002-11-04 10:13:36 arjen
+ Use proper namespace for iostream classes
+
+ Revision 1.1 2002/10/05 10:25:49 arjen
Creation of gcm_input and a first approach to a web interface
*****************************/
-static const char *RCSID = "$Id: gcm_input.cpp,v 1.1 2002-10-05 10:25:49 arjen Exp $";
+static const char *RCSID = "$Id: gcm_input.cpp,v 1.2 2002-11-04 10:13:36 arjen Exp $";
#include <getopt.h>
bool verbose = false;
bool testmode = false;
-static char *Version = "gcm_input version 0.0.3 - Sep 30, 2002";
+static char *Version = "gcm_input version 0.0.4 - Nov 05, 2002";
/*=========================================================================
arrival = String(optarg);
if (!arrival.proper())
{
- cerr << "gcm_input: Invalid date string: " << optarg << ".\n";
+ std::cerr << "gcm_input: Invalid date string: " << optarg << ".\n";
exit(1);
}
break;
break;
case 'V':
- cout << Version << "\n";
+ std::cout << Version << "\n";
exit(0);
case '?':
case ':':
- cerr << usage;
+ std::cerr << usage;
exit(1);
}
}
if (verbose)
{
- cout << "Hostname = " << hostname;
- cout << " Arrival = " << arrival;
- cout << " Service = " << service << "\n";
+ std::cout << "Hostname = " << hostname;
+ std::cout << " Arrival = " << arrival;
+ std::cout << " Service = " << service << "\n";
}
/* Get the configuration file */
if (!cfg.read(config_name))
{
- cerr << "Can not read Gnucomo configuration file for " << config_name << ".\n";
+ std::cerr << "Can not read Gnucomo configuration file for " << config_name << ".\n";
exit(1);
}
if (verbose)
{
- cout << "Config OK.\n";
+ std::cout << "Config OK.\n";
}
/* Try to connect to the database */
gnucomo_database db(&cfg);
- client_message msg(&cin, db);
+ client_message msg(&std::cin, db);
if (msg.classify(hostname, arrival, service) > 0.9)
{
***********************
** FILE NAME : message.cpp
** SYSTEM NAME : Gnucomo - Gnu Computer Monitoring
-** VERSION NUMBER : $Revision: 1.1 $
+** VERSION NUMBER : $Revision: 1.2 $
**
** DESCRIPTION : Implementation of the message handling classes
**
********************************
** ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
** CREATION DATE : Sep 16, 2002
-** LAST UPDATE : Oct 05, 2002
+** LAST UPDATE : Nov 04, 2002
** MODIFICATIONS :
**************************************************************************/
/*****************************
$Log: message.cpp,v $
- Revision 1.1 2002-10-05 10:25:49 arjen
+ Revision 1.2 2002-11-04 10:13:36 arjen
+ Use proper namespace for iostream classes
+
+ Revision 1.1 2002/10/05 10:25:49 arjen
Creation of gcm_input and a first approach to a web interface
*****************************/
-static const char *RCSID = "$Id: message.cpp,v 1.1 2002-10-05 10:25:49 arjen Exp $";
+static const char *RCSID = "$Id: message.cpp,v 1.2 2002-11-04 10:13:36 arjen Exp $";
#include "message.h"
** VARS CHANGED :
** FUNCTIONS USED :
** SEE ALSO :
-** LAST MODIFIED : Sep 30, 2002
+** LAST MODIFIED : Nov 04, 2002
**=========================================================================
*/
{
String l;
- //cout << " buffer is depleted.\n";
if (*(b.input) >> l)
{
b.buffer.push_back(l);
s = l;
input_ok = true;
- //cout << " new line from input.\n";
}
}
else
{
- //cout << " reading from cache.\n";
s = *(b.next_line);
b.next_line++;
input_ok = true;
return input_ok;
}
-client_message::client_message(istream *in, gnucomo_database db)
+client_message::client_message(std::istream *in, gnucomo_database db)
{
input.from(in);
database = db;
** VARS CHANGED :
** FUNCTIONS USED :
** SEE ALSO :
-** LAST MODIFIED : Oct 05, 2002
+** LAST MODIFIED : Nov 04, 2002
**=========================================================================
*/
while (input >> line && certainty < 0.9)
{
- cout << " testing: " << line << "\n";
+ std::cout << " testing: " << line << "\n";
if (line == re_syslog)
{
certainty = 1.0;
classification = SYSLOG;
if (verbose)
{
- cout << "Syslog detected.\n";
+ std::cout << "Syslog detected.\n";
}
}
else if (line == re_PGP)
{
certainty = 1.0;
gpg_encrypted = true;
- cerr << "The message is PGP/GnuPG encrypted.\n";
+ std::cerr << "The message is PGP/GnuPG encrypted.\n";
}
else if (line == re_dump)
{
certainty = 1.0;
if (verbose)
{
- cout << "DUMP output detected.\n";
+ std::cout << "DUMP output detected.\n";
}
}
else if (line == re_accesslog)
service = "httpd";
if (verbose)
{
- cout << "HTTP access log detected.\n";
+ std::cout << "HTTP access log detected.\n";
}
}
else if (line == re_errorlog)
service = "httpd";
if (verbose)
{
- cout << "HTTP error log detected.\n";
+ std::cout << "HTTP error log detected.\n";
}
}
}
if (hostname == "")
{
- cerr << "Can not determine the hostname where the message came from.\n";
+ std::cerr << "Can not determine the hostname where the message came from.\n";
certainty = 0.0;
}
else if (!arrival.proper())
{
- cerr << "Arrival time is not knwon.\n";
+ std::cerr << "Arrival time is not knwon.\n";
certainty = 0.0;
}
else
** VARS CHANGED :
** FUNCTIONS USED :
** SEE ALSO :
-** LAST MODIFIED : Oct 05, 2002
+** LAST MODIFIED : Nov 04, 2002
**=========================================================================
*/
objectid = database.find_host(hostname);
if (objectid == "")
{
- cerr << "Please define the host " << hostname << " in the database.\n";
+ std::cerr << "Please define the host " << hostname << " in the database.\n";
return 0;
}
if (verbose)
{
- cout << "Object id for " << hostname << " is " << objectid << "\n";
+ std::cout << "Object id for " << hostname << " is " << objectid << "\n";
}
/* Scan the input line by line, entring records into the database */
{
if (verbose)
{
- cout << line << "\n";
+ std::cout << line << "\n";
}
if (verbose)
{
- cout << " Log timestamp = " << log_date << " " << log_time << "\n";
+ std::cout << " Log timestamp = " << log_date << " " << log_time << "\n";
}
rest = line << 16;
i = rest.index(' ');
rest <<= i + 1;
if (verbose)
{
- cout << " Hostname matches.\n";
- cout << " rest = " << rest << "\n";
+ std::cout << " Hostname matches.\n";
+ std::cout << " rest = " << rest << "\n";
}
for (i = 0; isalpha(rest[i]) && i < ~rest; i++);
if (verbose)
{
- cout << " Service name = " << rest(0,i) << "\n";
+ std::cout << " Service name = " << rest(0,i) << "\n";
}
/* Insert a new record into the log table */
if (testmode)
{
- cout << insertion << "\n";
+ std::cout << insertion << "\n";
}
else
{
if (verbose)
{
- cout << "\n\n";
+ std::cout << "\n\n";
}
nr_lines++;
}
else
{
- cerr << " Hostname " << rest(0,i) << " does not match.\n";
+ std::cerr << " Hostname " << rest(0,i) << " does not match.\n";
}
break;
log_time = datestring;
if (verbose)
{
- cout << " Log timestamp = " << log_date << " " << log_time << "\n";
+ std::cout << " Log timestamp = " << log_date << " " << log_time << "\n";
}
insertion += "'" + objectid + "',";
insertion += "'" + service + "',";
if (testmode)
{
- cout << insertion << "\n";
+ std::cout << insertion << "\n";
}
else
{
if (verbose)
{
- cout << "\n\n";
+ std::cout << "\n\n";
}
nr_lines++;
log_time = datestring;
if (verbose)
{
- cout << " Log timestamp = " << log_date << " " << log_time << "\n";
+ std::cout << " Log timestamp = " << log_date << " " << log_time << "\n";
}
insertion += "'" + objectid + "',";
insertion += "'" + service + "',";
if (testmode)
{
- cout << insertion << "\n";
+ std::cout << insertion << "\n";
}
else
{
if (verbose)
{
- cout << "\n\n";
+ std::cout << "\n\n";
}
nr_lines++;
}
else
{
- cerr << "gcm_input WARNING: Not a valid line: " << line << "\n";
+ std::cerr << "gcm_input WARNING: Not a valid line: " << line << "\n";
}
}
if (verbose)
{
- cout << nr_lines << " lines parsed from the log file.\n";
+ std::cout << nr_lines << " lines parsed from the log file.\n";
}
return nr_lines;
}
***********************
** FILE NAME : message.h
** SYSTEM NAME :
-** VERSION NUMBER : $Revision: 1.1 $
+** VERSION NUMBER : $Revision: 1.2 $
**
** DESCRIPTION : Classes to for handling client messages
**
********************************
** ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
** CREATION DATE : Sep 16, 2002
-** LAST UPDATE : Oct 05, 2002
+** LAST UPDATE : Nov 04, 2002
** MODIFICATIONS :
**************************************************************************/
/*****************************
$Log: message.h,v $
- Revision 1.1 2002-10-05 10:25:49 arjen
+ Revision 1.2 2002-11-04 10:13:36 arjen
+ Use proper namespace for iostream classes
+
+ Revision 1.1 2002/10/05 10:25:49 arjen
Creation of gcm_input and a first approach to a web interface
*****************************/
-/* static const char *RCSID = "$Id: message.h,v 1.1 2002-10-05 10:25:49 arjen Exp $"; */
+/* static const char *RCSID = "$Id: message.h,v 1.2 2002-11-04 10:13:36 arjen Exp $"; */
#include <iostream>
#include <list>
//
// RELATIONS :
// SEE ALSO :
-// LAST MODIFIED : Sep 30, 2002
+// LAST MODIFIED : Nov 04, 2002
///////////////////////////////////////////////////////////////////////////
*/
class message_buffer
{
- istream *input;
- list<String> buffer;
+ std::istream *input;
+ std::list<String> buffer;
- list<String>::iterator next_line;
+ std::list<String>::iterator next_line;
public:
next_line = buffer.begin();
}
- message_buffer(istream *in)
+ message_buffer(std::istream *in)
{
input = in;
next_line = buffer.begin();
}
- void from(istream *in)
+ void from(std::istream *in)
{
input = in;
}
//
// RELATIONS :
// SEE ALSO :
-// LAST MODIFIED : Oct 05, 2002
+// LAST MODIFIED : Nov 04, 2002
///////////////////////////////////////////////////////////////////////////
*/
public:
- client_message(istream *in, gnucomo_database db);
+ client_message(std::istream *in, gnucomo_database db);
double classify(String host, UTC arrival = Now(), String serv = "");
int enter();
***********************
** FILE NAME : database.h
** SYSTEM NAME :
-** VERSION NUMBER : $Revision: 1.1 $
+** VERSION NUMBER : $Revision: 1.2 $
**
** DESCRIPTION : Classes to provide an abstract layer on the Gnucomo
** database.
********************************
** ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
** CREATION DATE : Sep 10, 2002
-** LAST UPDATE :
+** LAST UPDATE : Nov 04, 2002
** MODIFICATIONS :
**************************************************************************/
/*****************************
$Log: database.h,v $
- Revision 1.1 2002-10-05 10:25:49 arjen
+ Revision 1.2 2002-11-04 10:13:36 arjen
+ Use proper namespace for iostream classes
+
+ Revision 1.1 2002/10/05 10:25:49 arjen
Creation of gcm_input and a first approach to a web interface
*****************************/
-/* static const char *RCSID = "$Id: database.h,v 1.1 2002-10-05 10:25:49 arjen Exp $"; */
+/* static const char *RCSID = "$Id: database.h,v 1.2 2002-11-04 10:13:36 arjen Exp $"; */
#include <libpq++/pgdatabase.h>
#include "gnucomo_config.h"
}
else
{
- cerr << "Database query error: " << db->ErrorMessage() << "\n";
+ std::cerr << "Database query error: " << db->ErrorMessage() << "\n";
return -1;
}
}
***********************
** FILE NAME : database.cpp
** SYSTEM NAME : Gnucomo - Gnu Computer Monitoring
-** VERSION NUMBER : $Revision: 1.1 $
+** VERSION NUMBER : $Revision: 1.2 $
**
** DESCRIPTION : Implementation of the gnucomo database classes
**
********************************
** ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
** CREATION DATE : Sep 10, 2002
-** LAST UPDATE : Sep 26, 2002
+** LAST UPDATE : Nov 04, 2002
** MODIFICATIONS :
**************************************************************************/
/*****************************
$Log: database.cpp,v $
- Revision 1.1 2002-10-05 10:25:49 arjen
+ Revision 1.2 2002-11-04 10:13:36 arjen
+ Use proper namespace for iostream classes
+
+ Revision 1.1 2002/10/05 10:25:49 arjen
Creation of gcm_input and a first approach to a web interface
*****************************/
-static const char *RCSID = "$Id: database.cpp,v 1.1 2002-10-05 10:25:49 arjen Exp $";
+static const char *RCSID = "$Id: database.cpp,v 1.2 2002-11-04 10:13:36 arjen Exp $";
#include "database.h"
if (verbose)
{
- cout << "Database connection string = " << cfg->Database() << "\n";
+ std::cout << "Database connection string = " << cfg->Database() << "\n";
}
db = new PgDatabase(cfg->Database());
if (db->ConnectionBad())
{
- cerr << "Can not connect to database: " << db->ErrorMessage();
+ std::cerr << "Can not connect to database: " << db->ErrorMessage();
}
}
***********************
** FILE NAME : gnucomo_config.cpp
** SYSTEM NAME : Gnucomo - Gnu Computer Monitoring
-** VERSION NUMBER : $Revision: 1.1 $
+** VERSION NUMBER : $Revision: 1.2 $
**
** DESCRIPTION : Implementation of the gnucomo_config class.
**
********************************
** ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
** CREATION DATE : Jul 24, 2002
-** LAST UPDATE : Jul 24, 2002
+** LAST UPDATE : Nov 02, 2002
** MODIFICATIONS :
**************************************************************************/
/*****************************
$Log: gnucomo_config.cpp,v $
- Revision 1.1 2002-10-05 10:25:49 arjen
+ Revision 1.2 2002-11-04 10:13:36 arjen
+ Use proper namespace for iostream classes
+
+ Revision 1.1 2002/10/05 10:25:49 arjen
Creation of gcm_input and a first approach to a web interface
*****************************/
-static const char *RCSID = "$Id: gnucomo_config.cpp,v 1.1 2002-10-05 10:25:49 arjen Exp $";
+static const char *RCSID = "$Id: gnucomo_config.cpp,v 1.2 2002-11-04 10:13:36 arjen Exp $";
#include "gnucomo_config.h"
** VARS CHANGED :
** FUNCTIONS USED :
** SEE ALSO :
-** LAST MODIFIED :
+** LAST MODIFIED : Nov 02, 2002
**=========================================================================
*/
access_string += " password=" + param;
}
- /* FIXME: This needs a fix in the AXE library first */
-
- /*
param = find_parameter("database", "host");
if (param != "")
{
{
access_string += " port=" + param;
}
-*/
return access_string;
}
///////////////////////////////////////////////////////////////////////////
// NAME : gnucomo_config
// BASECLASS : configuration
-// MEMBERS :
+// MEMBERS :
// OPERATORS :
// METHODS : Database - Obtain the database access string
//
-// DESCRIPTION :
+// DESCRIPTION : Provides Gnucomo-specific configuration functions
//
// RELATIONS :
// SEE ALSO :
-// LAST MODIFIED :
+// LAST MODIFIED : Sep 26, 2002
///////////////////////////////////////////////////////////////////////////
*/
///////////////////////////////////////////////////////////////////////////
// NAME : gnucomo_config
// BASECLASS : configuration
-// MEMBERS :
+// MEMBERS :
// OPERATORS :
// METHODS : Database - Obtain the database access string
//
-// DESCRIPTION :
+// DESCRIPTION : Provides Gnucomo-specific configuration functions
//
// RELATIONS :
// SEE ALSO :
-// LAST MODIFIED :
+// LAST MODIFIED : Sep 26, 2002
///////////////////////////////////////////////////////////////////////////
*/