From d461d3a111b91c62c85ab197a4328c1108890c86 Mon Sep 17 00:00:00 2001 From: arjen Date: Sat, 18 Jan 2003 08:52:18 +0000 Subject: [PATCH] New C++ function: gnucomo_database::new_notification() --- src/include/database.h | 17 +++++++++---- src/lib/database.cpp | 66 +++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 74 insertions(+), 9 deletions(-) diff --git a/src/include/database.h b/src/include/database.h index 1a4763d..05cd32e 100644 --- a/src/include/database.h +++ b/src/include/database.h @@ -8,7 +8,7 @@ *********************** ** FILE NAME : database.h ** SYSTEM NAME : -** VERSION NUMBER : $Revision: 1.3 $ +** VERSION NUMBER : $Revision: 1.4 $ ** ** DESCRIPTION : Classes to provide an abstract layer on the Gnucomo ** database. @@ -21,13 +21,16 @@ ******************************** ** ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl ** CREATION DATE : Sep 10, 2002 -** LAST UPDATE : Nov 04, 2002 +** LAST UPDATE : Jan 17, 2003 ** MODIFICATIONS : **************************************************************************/ /***************************** $Log: database.h,v $ - Revision 1.3 2002-11-09 08:04:27 arjen + Revision 1.4 2003-01-18 08:52:18 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 @@ -38,7 +41,7 @@ *****************************/ -/* static const char *RCSID = "$Id: database.h,v 1.3 2002-11-09 08:04:27 arjen Exp $"; */ +/* static const char *RCSID = "$Id: database.h,v 1.4 2003-01-18 08:52:18 arjen Exp $"; */ #include #include "gnucomo_config.h" @@ -55,7 +58,7 @@ // // RELATIONS : // SEE ALSO : -// LAST MODIFIED : Sep 16, 2002 +// LAST MODIFIED : Jan 17, 2003 /////////////////////////////////////////////////////////////////////////// */ @@ -100,5 +103,9 @@ public: // Return the objectid of the host given its name. String find_host(const String hostname); + + // Create a new notification. + + void new_notification(String objectid, String issue, String remark); }; diff --git a/src/lib/database.cpp b/src/lib/database.cpp index c83f53e..9a20d6d 100644 --- a/src/lib/database.cpp +++ b/src/lib/database.cpp @@ -8,7 +8,7 @@ *********************** ** FILE NAME : database.cpp ** SYSTEM NAME : Gnucomo - Gnu Computer Monitoring -** VERSION NUMBER : $Revision: 1.3 $ +** VERSION NUMBER : $Revision: 1.4 $ ** ** DESCRIPTION : Implementation of the gnucomo database classes ** @@ -20,13 +20,16 @@ ******************************** ** ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl ** CREATION DATE : Sep 10, 2002 -** LAST UPDATE : Nov 04, 2002 +** LAST UPDATE : Jan 17, 2003 ** MODIFICATIONS : **************************************************************************/ /***************************** $Log: database.cpp,v $ - Revision 1.3 2002-11-09 08:04:27 arjen + 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 @@ -37,7 +40,9 @@ *****************************/ -static const char *RCSID = "$Id: database.cpp,v 1.3 2002-11-09 08:04:27 arjen Exp $"; +static const char *RCSID = "$Id: database.cpp,v 1.4 2003-01-18 08:52:32 arjen Exp $"; + +#include #include "database.h" @@ -112,3 +117,56 @@ String gnucomo_database::find_host(const String hostname) return objectid; } + +void gnucomo_database::new_notification(String objectid, String issue, String remark) +{ + String qry; + UTC now = Now(); + + String insertion; + String notif_id; + + String issueid(""); + + std::cout << "Creating notification for " << issue << "\n"; + + qry = "select type_of_issueid, suggested_priority from type_of_issue where name='"; + qry += issue + "'"; + if (Query(qry) == 1) + { + issueid = Field(0, "type_of_issueid"); + insertion = "insert into notification (objectid, type_of_issueid, timestamp, "; + insertion += " statuscode, priority) values ('"; + insertion += objectid + "', '"; + insertion += issueid + "', '" + now.format("%Y-%m-%d %T") + "', 'new', '"; + insertion += Field(0, "suggested_priority") + "')"; + + std::cout << insertion << "\n"; + + qry = "select notificationid from notification where objectid='"; + qry += objectid + "' and type_of_issueid = '"; + qry += issueid + "' order by notificationid"; + + Query(insertion); + int tuples = Query(qry); + + if (tuples > 0) + { + notif_id = Field(tuples - 1, "notificationid"); + + insertion = "insert into action_user (actionid, username, notificationid,"; + insertion += " timestamp, statuscode, remarks) values ('1', 'gnucomo', '"; + insertion += notif_id + "', '" + now.format("%Y-%m-%d %T") + "', 'new', '"; + insertion += remark + "')"; + + std::cout << insertion << "\n"; + Query(insertion); + } + else + { + std::cerr << "Error inserting notification.\n"; + exit(1); + } + } +} + -- 2.11.0