done
-ac_config_files="$ac_config_files Makefile src/Makefile src/gcm_input/Makefile src/lib/Makefile test/Makefile"
+ac_config_files="$ac_config_files Makefile src/Makefile src/lib/Makefile src/gcm_input/Makefile src/spam/Makefile test/Makefile"
cat >confcache <<\_ACEOF
# This file is a shell script that caches the results of configure
"depfiles") CONFIG_COMMANDS="$CONFIG_COMMANDS depfiles" ;;
"Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;;
"src/Makefile") CONFIG_FILES="$CONFIG_FILES src/Makefile" ;;
- "src/gcm_input/Makefile") CONFIG_FILES="$CONFIG_FILES src/gcm_input/Makefile" ;;
"src/lib/Makefile") CONFIG_FILES="$CONFIG_FILES src/lib/Makefile" ;;
+ "src/gcm_input/Makefile") CONFIG_FILES="$CONFIG_FILES src/gcm_input/Makefile" ;;
+ "src/spam/Makefile") CONFIG_FILES="$CONFIG_FILES src/spam/Makefile" ;;
"test/Makefile") CONFIG_FILES="$CONFIG_FILES test/Makefile" ;;
*) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;;
AC_CONFIG_FILES([Makefile
src/Makefile
- src/gcm_input/Makefile
src/lib/Makefile
+ src/gcm_input/Makefile
+ src/spam/Makefile
test/Makefile])
AC_OUTPUT
-SUBDIRS = lib gcm_input
+SUBDIRS = lib gcm_input spam
top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
-SUBDIRS = lib gcm_input
+SUBDIRS = lib gcm_input spam
all: all-recursive
.SUFFIXES:
#include <pqxx/result>
#include "gnucomo_config.h"
+#define DEBUG
+
/*
///////////////////////////////////////////////////////////////////////////
// NAME : gnucomo_database
class database_entity
{
- const gnucomo_database *db;
+ gnucomo_database *db;
String table;
+ String connected_table;
bool fresh; // Completely new, no tuple in the database
bool changed; // A database update is needed
bool deleted; // Tuple is to be deleted from the database
+protected:
+
+ std::map<String,String> fields;
+
public:
- database_entity(const gnucomo_database &gdb, const String tbl)
- {
- db = &gdb;
- table = tbl;
+ database_entity(gnucomo_database &gdb, const String tbl)
+ {
+ db = &gdb;
+ table = tbl;
+
+ fresh = true;
+ changed = false;
+ deleted = false;
+ }
+
+ // contruct a new database entity from the result of another one
+ database_entity(database_entity *from, int row);
+
+ int find_one(String key);
+ int find_many(String tab, String where);
- fresh = true;
- changed = false;
- deleted = false;
- }
};
** MODIFICATIONS :
**************************************************************************/
-/*****************************
- $Log: object.h,v $
- Revision 1.1 2007-02-02 07:36:39 arjen
- Started an object oriented abstraction of Gnucomo
+#include <date.h>
-*****************************/
-
-/* static const char *RCSID = "$Id: object.h,v 1.1 2007-02-02 07:36:39 arjen Exp $"; */
-
-#include "database.h"
+#include "objectlog.h"
/*
///////////////////////////////////////////////////////////////////////////
{
String hostname;
+ String id;
public:
- Object(const gnucomo_database &);
- Object(const gnucomo_database &, String);
+ Object(gnucomo_database &);
+ Object(gnucomo_database &, String);
String Hostname(); // Return the database access string.
+
+ std::list<ObjectLog> select_logs(UTC, UTC, String);
};
--- /dev/null
+
+/**************************************************************************
+** (c) Copyright 2005, Andromeda Technology & Automation
+** This is free software; you can redistribute it and/or modify it under the
+** terms of the GNU General Public License, see the file COPYING.
+***************************************************************************
+** MODULE INFORMATION *
+***********************
+** FILE NAME : objectlog.h
+** SYSTEM NAME :
+** VERSION NUMBER : $Revision: 1.1 $
+**
+** DESCRIPTION :
+**
+** EXPORTED OBJECTS :
+** LOCAL OBJECTS :
+** MODULES USED :
+***************************************************************************
+** ADMINISTRATIVE INFORMATION *
+********************************
+** ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
+** CREATION DATE : Mar 05, 2021
+** LAST UPDATE :
+** MODIFICATIONS :
+**************************************************************************/
+
+#include "database.h"
+
+/*
+///////////////////////////////////////////////////////////////////////////
+// NAME : ObjectLog
+// BASECLASS : database_entity
+// MEMBERS :
+// OPERATORS :
+// METHODS :
+//
+// DESCRIPTION :
+//
+// RELATIONS :
+// SEE ALSO :
+// LAST MODIFIED : Mar 05, 2021
+///////////////////////////////////////////////////////////////////////////
+*/
+
+class ObjectLog : public database_entity
+{
+
+ long id;
+
+public:
+
+ ObjectLog(gnucomo_database &);
+ ObjectLog(database_entity *from, int row) : database_entity(from, row)
+ {
+ }
+
+ String raw()
+ {
+ return fields["rawdata"];
+ }
+
+};
+
** MODIFICATIONS :
**************************************************************************/
-/*****************************
- $Log: database.cpp,v $
- Revision 1.13 2011-03-24 10:21:47 arjen
- Adjusted to new version of libpqxx.
-
- Revision 1.12 2003/12/22 10:28:26 arjen
- Catch an exception if we can not setup a database transaction.
-
- Revision 1.11 2003/12/04 10:40:28 arjen
- Fixed name conflict with 'double log(double)'
-
- Revision 1.10 2003/12/03 08:23:17 arjen
- Write messages to the log stream instead of cout.
-
- Revision 1.9 2003/08/17 11:39:56 arjen
- Changed the gnucomo_database class to the new PostgreSQL
- library, libpqxx
-
- Revision 1.8 2003/07/31 15:44:02 arjen
- Removed debug output.
-
- Revision 1.7 2003/02/19 12:07:55 arjen
- Use the SQL function currval() to obtain the identification number
- of the most recently created notification.
-
- Revision 1.6 2003/02/05 09:33:42 arjen
- gnucomo_database::new_notification() retruns the id number of the
- newly created notification record.
-
- Revision 1.5 2003/01/20 07:31:42 arjen
- Removed some debug output.
-
- Revision 1.4 2003/01/18 08:52:32 arjen
- New C++ function: gnucomo_database::new_notification()
-
- Revision 1.3 2002/11/09 08:04:27 arjen
- Added a reference to the GPL
-
- 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
-
-*****************************/
-
#include <date.h>
//#define DEBUG
{
// Create the transaction object
- //dbxact = new pqxx::transaction<pqxx::serializable>(*dbconn, "GnuCoMo");
dbxact = new pqxx::work(*dbconn, "GnuCoMo");
gdb_refcount++;
}
return notif_id;
}
+database_entity::database_entity(database_entity *from, int row)
+{
+ db = from->db;
+ table = from->connected_table;
+
+ int col;
+ pqxx::result res;
+
+ res = db->Result();
+
+ fresh = false;
+
+ for (col = 0; col < res.columns(); col++)
+ {
+ fields[res.column_name(col)] = res[row][col].c_str();
+ }
+}
+
+int database_entity::find_one(String key)
+{
+ String query("select * from ");
+
+ query += table;
+ query += " where ";
+ query += key;
+
+ if ( db->Query(query) == 1)
+ {
+ int col;
+ pqxx::result res;
+
+ res = db->Result();
+
+ fresh = false;
+
+ for (col = 0; col < res.columns(); col++)
+ {
+ std::cerr << "Field[" << col << "] " << res.column_name(col);
+ std::cerr << " = " << res[0][col].c_str() << "\n";
+
+ fields[res.column_name(col)] = res[0][col].c_str();
+ }
+
+ return 1;
+ }
+ return 0;
+}
+
+int database_entity::find_many(String tab, String where)
+{
+ connected_table = tab;
+
+ String query("select * from ");
+
+ query += tab;
+ query += " where ";
+ query += where;
+
+ return db->Query(query);
+
+}
+
**=========================================================================
*/
-Object::Object(const gnucomo_database &db) : database_entity(db, "object")
+Object::Object(gnucomo_database &gdb) : database_entity(gdb, "object")
{
+ id = "0";
+ hostname = "";
}
+Object::Object(gnucomo_database &gdb, String name) : database_entity(gdb, "object")
+{
+ id = "0";
+ hostname = name;
+
+ String objectid("");
+ String check_host;
+
+ check_host += "objectname = '";
+ check_host += hostname;
+ check_host += "'";
+
+ if (find_one(check_host) > 0)
+ {
+ id = fields["objectid"];
+ std::cerr << "Object id = " << id << "\n";
+ }
+
+}
+
+std::list<ObjectLog> Object::select_logs(UTC start, UTC finish, String service)
+{
+
+ int rows_found;
+ std::list<ObjectLog> logs;
+
+ String where("objectid=");
+
+ where += id;
+ where += " and timestamp >= '";
+ where += start.format();
+ where += "' and timestamp <= '";
+ where += finish.format();
+ where += "' and servicecode = '";
+ where += service;
+ where += "'";
+
+ rows_found = find_many("log", where);
+
+ for (int r = 0; r < rows_found; r++)
+ {
+ ObjectLog ol(this, r);
+ logs.push_back(ol);
+ }
+
+ return logs;
+}