***********************
** 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.
********************************
** 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
*****************************/
-/* 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 <libpq++/pgdatabase.h>
#include "gnucomo_config.h"
//
// RELATIONS :
// SEE ALSO :
-// LAST MODIFIED : Sep 16, 2002
+// LAST MODIFIED : Jan 17, 2003
///////////////////////////////////////////////////////////////////////////
*/
// 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);
};
***********************
** 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
**
********************************
** 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
*****************************/
-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 <AXE/date.h>
#include "database.h"
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);
+ }
+ }
+}
+