[icinga-checkins] icinga.org: icinga-core/tdressler/sqlite: idoutils: sqlite add missed time functions, set localtime #3945

git at icinga.org git at icinga.org
Wed Apr 10 22:27:46 CEST 2013


Module: icinga-core
Branch: tdressler/sqlite
Commit: e075a8a136b26dc5d6594a055735cbf3c4fc1a36
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=e075a8a136b26dc5d6594a055735cbf3c4fc1a36

Author: Thomas Dressler <tdressler at tdressler.net>
Date:   Wed Apr 10 22:25:54 2013 +0200

idoutils: sqlite add missed time functions, set localtime #3945
refs #3945

---

 module/idoutils/src/db.c |   19 +++++++++++++++----
 1 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/module/idoutils/src/db.c b/module/idoutils/src/db.c
index 2340d54..accf290 100644
--- a/module/idoutils/src/db.c
+++ b/module/idoutils/src/db.c
@@ -1665,7 +1665,7 @@ int ido2db_db_hello(ido2db_idi *idi) {
 			case IDO2DB_DBSERVER_SQLITE3:
 				if (asprintf(&buf, "INSERT INTO %s (instance_id, connect_time, last_checkin_time, bytes_processed, lines_processed, entries_processed, "
 							"agent_name, agent_version, disposition, connect_source, connect_type, data_start_time) "
-							"VALUES (%lu, datetime('now'), datetime('now'), '0', '0', '0', '%s', '%s', '%s', '%s', '%s', datetime('now'))",
+							"VALUES (%lu, datetime('now','localtime'), datetime('now','localtime'), '0', '0', '0', '%s', '%s', '%s', '%s', '%s', datetime('now','localtime'))",
 					             ido2db_db_tablenames[IDO2DB_DBTABLE_CONNINFO],
 					             idi->dbinfo.instance_id, idi->agent_name, idi->agent_version,
 					             idi->disposition, idi->connect_source, idi->connect_type) == -1)
@@ -1996,7 +1996,7 @@ int ido2db_thread_db_hello(ido2db_idi *idi) {
 				case IDO2DB_DBSERVER_SQLITE3:
 					if (asprintf(&buf, "INSERT INTO %s (instance_id, connect_time, last_checkin_time, bytes_processed, lines_processed, entries_processed, "
 						    "agent_name, agent_version, disposition, connect_source, connect_type, data_start_time) "
-						    "VALUES (%lu, datetime('now'), datetime('now'), '0', '0', '0', '%s', '%s', '%s', '%s', '%s', datetime('now'))",
+						    "VALUES (%lu, datetime('now','localtime'), datetime('now','localtime'), '0', '0', '0', '%s', '%s', '%s', '%s', '%s', datetime('now','localtime'))",
 						    ido2db_db_tablenames[IDO2DB_DBTABLE_CONNINFO],
 						    idi->dbinfo.instance_id, idi->agent_name, idi->agent_version,
 						    idi->disposition, idi->connect_source, idi->connect_type) == -1)
@@ -2214,7 +2214,7 @@ int ido2db_db_goodbye(ido2db_idi *idi) {
 				case IDO2DB_DBSERVER_SQLITE:
 				case IDO2DB_DBSERVER_SQLITE3:
 					/* record last connection information */
-					if (asprintf(&buf, "UPDATE %s SET disconnect_time=datetime('now'), last_checkin_time=datetime('now'), data_end_time=%s, bytes_processed=%lu, lines_processed=%lu, entries_processed=%lu WHERE conninfo_id=%lu",
+					if (asprintf(&buf, "UPDATE %s SET disconnect_time=datetime('now','localtime'), last_checkin_time=datetime('now','localtime'), data_end_time=%s, bytes_processed=%lu, lines_processed=%lu, entries_processed=%lu WHERE conninfo_id=%lu",
 							ido2db_db_tablenames[IDO2DB_DBTABLE_CONNINFO], ts,
 							idi->bytes_processed, idi->lines_processed, idi->entries_processed,
 							idi->dbinfo.conninfo_id) == -1)
@@ -2310,7 +2310,7 @@ int ido2db_db_checkin(ido2db_idi *idi) {
 	switch (idi->dbinfo.server_type) {
 		case IDO2DB_DBSERVER_SQLITE:
 		case IDO2DB_DBSERVER_SQLITE3:
-			if (asprintf(&buf, "UPDATE %s SET last_checkin_time=datetime('now'), bytes_processed=%lu, lines_processed=%lu, entries_processed=%lu WHERE conninfo_id=%lu",
+			if (asprintf(&buf, "UPDATE %s SET last_checkin_time=datetime('now','localtime'), bytes_processed=%lu, lines_processed=%lu, entries_processed=%lu WHERE conninfo_id=%lu",
 						ido2db_db_tablenames[IDO2DB_DBTABLE_CONNINFO],
 						idi->bytes_processed, idi->lines_processed, idi->entries_processed,
 						idi->dbinfo.conninfo_id) == -1)
@@ -2486,6 +2486,12 @@ char *ido2db_db_timet_to_sql(ido2db_idi *idi, time_t t) {
 	ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_timet_to_sql(%lu) start\n", (unsigned long)t);
 
 	switch (idi->dbinfo.server_type) {
+	case IDO2DB_DBSERVER_SQLITE:
+	case IDO2DB_DBSERVER_SQLITE3:
+		if (asprintf(&buf, "datetime(%lu, 'unixepoch','localtime')", (unsigned long) t) == -1)
+					buf = NULL;
+				break;
+		break;
 	case IDO2DB_DBSERVER_MYSQL:
 		/* mysql from_unixtime treats 0 as 'Out of range value for column '...' at row 1'
 		 * which basically is a mess, when doing updates at all. in order to stay sane, we
@@ -2528,6 +2534,11 @@ char *ido2db_db_sql_to_timet(ido2db_idi *idi, char *field) {
 	ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_sql_to_timet(%s) start\n", field);
 
 	switch (idi->dbinfo.server_type) {
+	case IDO2DB_DBSERVER_SQLITE:
+	case IDO2DB_DBSERVER_SQLITE3:
+			if (asprintf(&buf, "strftime('%%s','%s','localtime')", (field == NULL) ? "" : field) == -1)
+				buf = NULL;
+			break;
 	case IDO2DB_DBSERVER_MYSQL:
 		if (asprintf(&buf, "UNIX_TIMESTAMP(%s)", (field == NULL) ? "" : field) == -1)
 			buf = NULL;





More information about the icinga-checkins mailing list