aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar aldot <aldot@5e8054f6-fb45-0410-9d17-f830fe724320>2009-04-10 19:03:11 +0000
committerGravatar aldot <aldot@5e8054f6-fb45-0410-9d17-f830fe724320>2009-04-10 19:03:11 +0000
commit8c133744fa42b466618c5803632b22ebee377ea5 (patch)
treeb47887fcb6db4296a997f98a9877027ac3f66a60
parent8f226d498f88f2cb564d1ece0c741473572aab8e (diff)
downloadndoutils-oracle-8c133744fa42b466618c5803632b22ebee377ea5.tar.gz
ndoutils-oracle-8c133744fa42b466618c5803632b22ebee377ea5.tar.bz2
- convert CONTACT_NOTIFICATION_COMMANDS to parameter binding
- alot of robustness improvements git-svn-id: https://www.nagiosforge.org/svn/ndoutils_oracle/trunk/ndoutils-1.4b7-oracle@83 5e8054f6-fb45-0410-9d17-f830fe724320
-rw-r--r--liboci/include/liboci.h1
-rw-r--r--liboci/src/liboci.c856
-rw-r--r--src/dbhandlers.c43
3 files changed, 598 insertions, 302 deletions
diff --git a/liboci/include/liboci.h b/liboci/include/liboci.h
index bad3ce5..f9332cf 100644
--- a/liboci/include/liboci.h
+++ b/liboci/include/liboci.h
@@ -15,6 +15,7 @@
#define LIBOCI_DEFAULT 0
#define LIBOCI_MERGE_SERVICESTATUS 11
#define LIBOCI_MERGE_SERVICECHECKS 12
+#define LIBOCI_MERGE_CONTACT_NOTIFICATION_COMMANDS 13
int ora_oci_init(void);
int ora_oci_connect(char *username, char *password, char *database);
diff --git a/liboci/src/liboci.c b/liboci/src/liboci.c
index a2f5895..510a436 100644
--- a/liboci/src/liboci.c
+++ b/liboci/src/liboci.c
@@ -7,6 +7,7 @@ static OCISvcCtx *p_svc; /* Service Context Handle */
static OCIStmt *p_sql; /* Statement Handle */
static OCIStmt *p_sql_servicestatus; /* Statement Handle */
static OCIStmt *p_sql_servicechecks; /* Statement Handle */
+static OCIStmt *p_sql_contact_notifcmds; /* Statement Handle */
static OCIBind *p_bnd = (OCIBind *) 0;
void *row[100]; /* if a query returns more then 100 columns this value has to be increased */
unsigned short counter = 0; /* keep track of how many pointers have been memory assigned to */
@@ -14,25 +15,104 @@ unsigned long insert_id = -1; /* insert id of the latest sql query */
int rc = OCI_SUCCESS; /* return value */
char error_msg[512];
-static void ndo2db_log(char *msg)
-{
+
#if 0
- printf("%s\n", msg);
- FILE *file;
+FILE *file = NULL;
+static void ndo2db_log(const char *fmt, ...)
+{
- file = fopen("/opt/nagios/var/ndo2db_debug.log", "a+");
+ if (file == NULL)
+ file = fopen("/opt/nagios/var/ndo2db_debug.log", "a+");
if (file != NULL) {
- char s[128];
+ char d[128];
+ char s[1024];
time_t t = time(0);
struct tm *now = localtime(&t);
+ va_list ap;
- strftime(s, sizeof(s), "[%Y-%m-%d %H:%M:%S]", now);
- fprintf(file, "%s [%d] %s\n\n", s, getpid(), msg);
- fclose(file);
+ va_start(ap, fmt);
+ vsnprintf(s, 1024 - 1, fmt, ap);
+ va_end(ap);
+
+ strftime(d, sizeof(d), "[%Y-%m-%d %H:%M:%S]", now);
+ fprintf(file, "%s [%d] %s\n\n", d, getpid(), s);
+ fflush(file);
+/* fclose(file); */
}
+}
+#else
+static void ndo2db_log(const char *unused, ...)
+{
+}
#endif
+
+static void clear_error(void)
+{
+ memset(error_msg, 0, sizeof(error_msg));
+}
+
+char *ora_oci_error(void)
+{
+ char *ret = strdup(error_msg);
+
+ clear_error();
+ return ret;
+}
+
+sword checkerr(OCIError * p_err, sword status)
+{
+ char m[512];
+ char *err_name = NULL;
+ sb4 errcode = 0;
+ sword ret = status;
+
+ if (status == OCI_SUCCESS) {
+ clear_error();
+ return ret;
+ } else if (status == OCI_SUCCESS_WITH_INFO) {
+ ret = OCI_SUCCESS; /* this is not an error */
+ (void) OCIErrorGet((dvoid *) p_err, (ub4) 1, (text *) NULL,
+ &errcode, (text *) error_msg,
+ (ub4) sizeof(error_msg), OCI_HTYPE_ERROR);
+ sprintf(m, "Info - (%d) %d: %s", status, errcode, error_msg);
+ strcpy(error_msg, m);
+ ndo2db_log("%s", m);
+ return ret;
+ }
+
+ (void) OCIErrorGet((dvoid *) p_err, (ub4) 1, (text *) NULL,
+ &errcode, (text *) error_msg,
+ (ub4) sizeof(error_msg), OCI_HTYPE_ERROR);
+
+ switch (status) {
+ case OCI_NEED_DATA:
+ err_name = "OCI_NEED_DATA";
+ break;
+ case OCI_NO_DATA:
+ err_name = "OCI_NO_DATA";
+ break;
+ case OCI_INVALID_HANDLE:
+ err_name = "OCI_INVALID_HANDLE";
+ break;
+ case OCI_STILL_EXECUTING:
+ err_name = "OCI_STILL_EXECUTING";
+ break;
+ case OCI_CONTINUE:
+ err_name = "OCI_CONTINUE";
+ break;
+ case OCI_ERROR:
+ err_name = "OCI_ERROR";
+ break;
+ }
+ sprintf(m, "Error - %s (%d) %d, %s", err_name ? err_name : "", status,
+ errcode, error_msg);
+ strcpy(error_msg, m);
+
+ return ret;
}
+
+
/* Initialize OCI Environment */
int ora_oci_init(void)
{
@@ -73,7 +153,8 @@ int ora_oci_connect(char *username, char *password, char *database)
(text *) database, strlen(database));
rc = checkerr(p_err, rc);
if (rc != OCI_SUCCESS) {
- ndo2db_log("Could not connect to database.");
+ ndo2db_log("Could not connect to database %s",
+ ora_oci_error());
return (0);
} else {
ndo2db_log("Successfully connected to database.");
@@ -88,7 +169,7 @@ int ora_oci_ping(void)
rc = checkerr(p_err, rc);
if (rc != OCI_SUCCESS) {
- ndo2db_log("Failed to ping the database.");
+ ndo2db_log("Failed to ping the database %s", ora_oci_error());
return (0);
} else {
ndo2db_log("Successfully pinged the database.");
@@ -103,7 +184,8 @@ int ora_oci_ping(void)
*/
int ora_oci_query(char *q)
{
- ndo2db_log(q);
+ ndo2db_log("%s", q);
+ clear_error();
if (!strncasecmp("SELECT", q, 6)) {
rc = ora_oci_select(q);
return (rc);
@@ -262,7 +344,6 @@ int ora_oci_select(char *q)
case SQLT_INT:
case SQLT_NUM:
row[counter - 1] = malloc(sizeof(long));
- /* printf("sizeof(long)=%i\n", sizeof(long)); */
rc = OCIDefineByPos(p_sql, &p_dfn, p_err, counter,
(dvoid *) row[counter - 1],
sizeof(long), SQLT_INT,
@@ -284,7 +365,6 @@ int ora_oci_select(char *q)
return (-1);
break;
case SQLT_DAT:
- /* printf("Its a Date\n"); */
row[counter - 1] = malloc(sizeof(char) * 80);
rc = OCIDefineByPos(p_sql, &p_dfn, p_err, counter,
(dvoid *) row[counter - 1], 80,
@@ -297,7 +377,7 @@ int ora_oci_select(char *q)
default:
sprintf(error_msg, "Error - Unsupported Datatype: %d",
dtype);
- ndo2db_log(error_msg);
+ ndo2db_log("%s", error_msg);
break;
}
@@ -354,95 +434,53 @@ int ora_oci_disconnect(void)
if (rc != OCI_SUCCESS)
return (-1);
ndo2db_log("Successfully disconnected from database.");
+ clear_error();
return (0);
}
unsigned long ora_oci_insert_id(void)
{
void **ii;
+ int i;
- ora_oci_select("SELECT AUTOINCREMENT.CURRVAL FROM DUAL");
+ i = ora_oci_select("SELECT AUTOINCREMENT.CURRVAL FROM DUAL");
ii = ora_oci_fetch_row(p_sql);
+ if (ii == NULL) {
+ i = checkerr(p_err, i);
+ ndo2db_log("Fatal error: no new id! %s", ora_oci_error());
+ _exit(1);
+ }
insert_id = *(unsigned long *) ii[0];
/* *(unsigned long *)idi->dbinfo.oracle_row[0] */
ora_oci_free_result(p_sql);
return insert_id;
}
-char *ora_oci_error(void)
-{
- return error_msg;
-}
-
-sword checkerr(OCIError * p_err, sword status)
-{
- char m[512];
- sb4 errcode = 0;
- sword ret = status;
-
- switch (status) {
- case OCI_SUCCESS:
- break;
- case OCI_SUCCESS_WITH_INFO:
- ret = OCI_SUCCESS; /* this is not an error */
- (void) OCIErrorGet((dvoid *) p_err, (ub4) 1, (text *) NULL,
- &errcode, (text *) error_msg,
- (ub4) sizeof(error_msg), OCI_HTYPE_ERROR);
- sprintf(m, "Info - (%d) %d: %s", status, errcode, error_msg);
- strcpy(error_msg, m);
- ndo2db_log(m);
- break;
- case OCI_NEED_DATA:
- sprintf(error_msg, "Error - OCI_NEED_DATA");
- ndo2db_log(error_msg);
- break;
- case OCI_NO_DATA:
- sprintf(error_msg, "Error - OCI_NO_DATA");
- ndo2db_log(error_msg);
- break;
- case OCI_INVALID_HANDLE:
- sprintf(error_msg, "Error - OCI_INVALID_HANDLE");
- ndo2db_log(error_msg);
- break;
- case OCI_STILL_EXECUTING:
- sprintf(error_msg, "Error - OCI_STILL_EXECUTING");
- ndo2db_log(error_msg);
- break;
- case OCI_CONTINUE:
- sprintf(error_msg, "Error - OCI_CONTINUE");
- ndo2db_log(error_msg);
- break;
- case OCI_ERROR:
- default:
- (void) OCIErrorGet((dvoid *) p_err, (ub4) 1, (text *) NULL,
- &errcode, (text *) error_msg,
- (ub4) sizeof(error_msg), OCI_HTYPE_ERROR);
- sprintf(m, "Error - (%d) %d: %s", status, errcode, error_msg);
- strcpy(error_msg, m);
- ndo2db_log(m);
- break;
- }
- return ret;
-}
-
-static int ora_oci_prepare_one_statement(const char * const query, OCIStmt * bind_stmt)
+/* Setup one statement's parameter bindings.
+ * Returns OCI_SUCCESS (0) on success, an OCI ERROR code otherwise.
+ */
+static int ora_oci_prepare_one_statement(const char *const query,
+ OCIStmt ** bind_stmt)
{
- rc = OCIHandleAlloc((dvoid *) p_env, (dvoid **) &bind_stmt,
+ rc = OCIHandleAlloc((dvoid *) p_env, (dvoid **) bind_stmt,
OCI_HTYPE_STMT, (size_t) 0, (dvoid **) 0);
rc = checkerr(p_err, rc);
if (rc != OCI_SUCCESS)
return (rc);
- rc = OCIStmtPrepare(bind_stmt, p_err, (text *) query,
+ rc = OCIStmtPrepare(*(OCIStmt **) bind_stmt, p_err, (text *) query,
(ub4) strlen(query), (ub4) OCI_NTV_SYNTAX,
(ub4) OCI_DEFAULT);
rc = checkerr(p_err, rc);
+
if (rc != OCI_SUCCESS) {
- OCIHandleFree((dvoid *) bind_stmt,
- OCI_HTYPE_STMT);
+ OCIHandleFree(*bind_stmt, OCI_HTYPE_STMT);
}
return (rc);
}
+/* Prepare all statements that do parameter binding.
+ * Return 1 on success, 0 otherwise.
+ */
int ora_oci_prepare_statements(void)
{
int i, ret = OCI_SUCCESS;
@@ -589,11 +627,13 @@ int ora_oci_prepare_statements(void)
:X45, \
:X46 \
)";
- i = ora_oci_prepare_one_statement(q, p_sql_servicestatus);
+ i = ora_oci_prepare_one_statement(q, &p_sql_servicestatus);
if (i == OCI_SUCCESS) {
- ndo2db_log("Servicestatus Merge Statement successfully prepared.");
+ ndo2db_log
+ ("Servicestatus Merge Statement successfully prepared.");
} else {
- ndo2db_log("Error: Servicestatus Merge Statement binding failed.");
+ ndo2db_log
+ ("Error: Servicestatus Merge Statement binding failed.");
ret = i;
}
@@ -662,283 +702,509 @@ int ora_oci_prepare_statements(void)
:X20, \
:X21\
)";
- i = ora_oci_prepare_one_statement(q, p_sql_servicechecks);
+ i = ora_oci_prepare_one_statement(q, &p_sql_servicechecks);
if (i == OCI_SUCCESS) {
- ndo2db_log("Servicecheck Merge Statement successfully prepared.");
+ ndo2db_log
+ ("Servicecheck Merge Statement successfully prepared.");
} else {
- ndo2db_log("Error: Servicecheck Merge Statement binding failed.");
+ ndo2db_log
+ ("Error: Servicecheck Merge Statement binding failed.");
ret = i;
}
+
+ q = "MERGE INTO nagios_contact_notifcmds USING DUAL ON ( \
+ instance_id=:X1 AND \
+ contact_id=:X2 AND \
+ notification_type=:X3 AND \
+ command_object_id=:X4 \
+ ) WHEN MATCHED THEN UPDATE SET \
+ command_args=':X5' \
+ WHEN NOT MATCHED THEN INSERT ( \
+ instance_id, \
+ contact_id, \
+ notification_type, \
+ command_object_id, \
+ command_args \
+ ) VALUES ( \
+ :X1, \
+ :X2, \
+ :X3, \
+ :X4, \
+ :X5 \
+ )";
+ i = ora_oci_prepare_one_statement(q, &p_sql_contact_notifcmds);
+ if (i == OCI_SUCCESS) {
+ ndo2db_log
+ ("Contact_notifcmds Merge Statement successfully prepared.");
+ } else {
+ ndo2db_log
+ ("Error: Contact_notifcmds Merge Statement binding failed.");
+ ret = i;
+ }
+
return ret == OCI_SUCCESS;
}
-static int ora_oci_bind_char(OCIStmt * p_stmt, text * varname, dvoid * value)
+static int bind_char(OCIStmt * p_stmt, char *varname, dvoid * value)
{
- rc = OCIBindByName(p_stmt, &p_bnd, p_err, varname, -1, value,
- strlen(value) + 1, SQLT_CHR, (dvoid *) 0,
- (ub2 *) 0, (ub2 *) 0, (ub4) 0, (ub4 *) 0,
- OCI_DEFAULT);
+ char *val = (char *) value;
+ sb4 indicator = 0;
+
+ if (val == NULL) {
+ val = "";
+ indicator = -1;
+ }
+ rc = OCIBindByName(p_stmt, &p_bnd, p_err, (text *) varname, -1,
+ val, strlen(val) + 1,
+ SQLT_CHR, (dvoid *) & indicator, (ub2 *) 0,
+ (ub2 *) 0, (ub4) 0, (ub4 *) 0, OCI_DEFAULT);
rc = checkerr(p_err, rc);
if (rc != OCI_SUCCESS)
- return (-1);
- return (0);
+ ndo2db_log("Error: bind_char '%s' %s", varname,
+ ora_oci_error());
+ return (rc);
}
-static int ora_oci_bind_int(OCIStmt * p_stmt, text * varname, dvoid * value)
+static int bind_int(OCIStmt * p_stmt, char *varname, dvoid * value)
{
- rc = OCIBindByName(p_stmt, &p_bnd, p_err, varname, -1, value,
- sizeof(int), SQLT_INT, (dvoid *) 0, (ub2 *) 0,
- (ub2 *) 0, (ub4) 0, (ub4 *) 0, OCI_DEFAULT);
+ rc = OCIBindByName(p_stmt, &p_bnd, p_err, (text *) varname,
+ -1, value, sizeof(int),
+ SQLT_INT, (dvoid *) 0, (ub2 *) 0, (ub2 *) 0,
+ (ub4) 0, (ub4 *) 0, OCI_DEFAULT);
rc = checkerr(p_err, rc);
if (rc != OCI_SUCCESS)
- return (-1);
- return (0);
+ ndo2db_log("Error: bind_int '%s' %s", varname,
+ ora_oci_error());
+ return (rc);
}
-static int ora_oci_bind_long(OCIStmt * p_stmt, text * varname, dvoid * value)
+static int bind_long(OCIStmt * p_stmt, char *varname, dvoid * value)
{
- rc = OCIBindByName(p_stmt, &p_bnd, p_err, varname, -1, value,
+ rc = OCIBindByName(p_stmt, &p_bnd, p_err, (text *) varname,
+ -1, value,
sizeof(unsigned long), SQLT_UIN, (dvoid *) 0,
(ub2 *) 0, (ub2 *) 0, (ub4) 0, (ub4 *) 0,
OCI_DEFAULT);
rc = checkerr(p_err, rc);
if (rc != OCI_SUCCESS)
- return (-1);
- return (0);
+ ndo2db_log("Error: bind_long '%s' %s", varname,
+ ora_oci_error());
+ return (rc);
}
-static int ora_oci_bind_float(OCIStmt * p_stmt, text * varname, dvoid * value)
+static int bind_float(OCIStmt * p_stmt, char *varname, dvoid * value)
{
- rc = OCIBindByName(p_stmt, &p_bnd, p_err, varname, -1, value,
- sizeof(float), SQLT_FLT, (dvoid *) 0, (ub2 *) 0,
- (ub2 *) 0, (ub4) 0, (ub4 *) 0, OCI_DEFAULT);
+ rc = OCIBindByName(p_stmt, &p_bnd, p_err, (text *) varname,
+ -1, value, sizeof(float),
+ SQLT_FLT, (dvoid *) 0, (ub2 *) 0, (ub2 *) 0,
+ (ub4) 0, (ub4 *) 0, OCI_DEFAULT);
rc = checkerr(p_err, rc);
if (rc != OCI_SUCCESS)
- return (-1);
- return (0);
+ ndo2db_log("Error: bind_float '%s' %s", varname,
+ ora_oci_error());
+ return (rc);
}
-static int ora_oci_bind_date(OCIStmt * p_stmt, text * varname, dvoid * value)
+static int bind_date(OCIStmt * p_stmt, char *varname, dvoid * value)
{
- rc = OCIBindByName(p_stmt, &p_bnd, p_err, varname, -1, value, 9,
- SQLT_DAT, (dvoid *) 0, (ub2 *) 0, (ub2 *) 0,
- (ub4) 0, (ub4 *) 0, OCI_DEFAULT);
+ rc = OCIBindByName(p_stmt, &p_bnd, p_err, (text *) varname,
+ -1, value, 9, SQLT_DAT,
+ (dvoid *) 0, (ub2 *) 0, (ub2 *) 0, (ub4) 0,
+ (ub4 *) 0, OCI_DEFAULT);
rc = checkerr(p_err, rc);
if (rc != OCI_SUCCESS)
- return (-1);
- return (0);
+ ndo2db_log("Error: bind_date '%s' %s", varname,
+ ora_oci_error());
+ return (rc);
}
-static int ora_oci_merge_servicestatus(unsigned long v1, unsigned long v2,
- unsigned long v3, char *v4, char *v5, int v6,
- int v7, int v8, int v9, int v10,
- unsigned long v11, unsigned long v12, int v13,
- unsigned long v14, unsigned long v15, int v16,
- unsigned long v17, unsigned long v18,
- unsigned long v19, unsigned long v20, int v21,
- unsigned long v22, unsigned long v23, int v24,
- int v25, int v26, int v27, int v28, int v29,
- int v30, int v31, int v32, int v33, float v34,
- float v35, float v36, int v37, int v38,
- int v39, int v40, unsigned long v41,
- char *v42, char *v43, float v44, float v45,
- unsigned long v46)
+static int merge_servicestatus(unsigned long v1, unsigned long v2,
+ unsigned long v3, char *v4, char *v5,
+ int v6, int v7, int v8, int v9,
+ int v10, unsigned long v11,
+ unsigned long v12, int v13,
+ unsigned long v14, unsigned long v15,
+ int v16, unsigned long v17,
+ unsigned long v18, unsigned long v19,
+ unsigned long v20, int v21,
+ unsigned long v22, unsigned long v23,
+ int v24, int v25, int v26, int v27,
+ int v28, int v29, int v30, int v31,
+ int v32, int v33, float v34, float v35,
+ float v36, int v37, int v38, int v39,
+ int v40, unsigned long v41, char *v42,
+ char *v43, float v44, float v45,
+ unsigned long v46)
{
- ora_oci_bind_long(p_sql_servicestatus, ":X1", &v1);
- ora_oci_bind_long(p_sql_servicestatus, ":X2", &v2);
- ora_oci_bind_long(p_sql_servicestatus, ":X3", &v3);
- ora_oci_bind_char(p_sql_servicestatus, ":X4", v4);
- ora_oci_bind_char(p_sql_servicestatus, ":X5", v5);
- ora_oci_bind_int(p_sql_servicestatus, ":X6", &v6);
- ora_oci_bind_int(p_sql_servicestatus, ":X7", &v7);
- ora_oci_bind_int(p_sql_servicestatus, ":X8", &v8);
- ora_oci_bind_int(p_sql_servicestatus, ":X9", &v9);
- ora_oci_bind_int(p_sql_servicestatus, ":X10", &v10);
- ora_oci_bind_long(p_sql_servicestatus, ":X11", &v11);
- ora_oci_bind_long(p_sql_servicestatus, ":X12", &v12);
- ora_oci_bind_int(p_sql_servicestatus, ":X13", &v13);
- ora_oci_bind_long(p_sql_servicestatus, ":X14", &v14);
- ora_oci_bind_long(p_sql_servicestatus, ":X15", &v15);
- ora_oci_bind_int(p_sql_servicestatus, ":X16", &v16);
- ora_oci_bind_long(p_sql_servicestatus, ":X17", &v17);
- ora_oci_bind_long(p_sql_servicestatus, ":X18", &v18);
- ora_oci_bind_long(p_sql_servicestatus, ":X19", &v19);
- ora_oci_bind_long(p_sql_servicestatus, ":X20", &v20);
- ora_oci_bind_int(p_sql_servicestatus, ":X21", &v21);
- ora_oci_bind_long(p_sql_servicestatus, ":X22", &v22);
- ora_oci_bind_long(p_sql_servicestatus, ":X23", &v23);
- ora_oci_bind_int(p_sql_servicestatus, ":X24", &v24);
- ora_oci_bind_int(p_sql_servicestatus, ":X25", &v25);
- ora_oci_bind_int(p_sql_servicestatus, ":X26", &v26);
- ora_oci_bind_int(p_sql_servicestatus, ":X27", &v27);
- ora_oci_bind_int(p_sql_servicestatus, ":X28", &v28);
- ora_oci_bind_int(p_sql_servicestatus, ":X29", &v29);
- ora_oci_bind_int(p_sql_servicestatus, ":X30", &v30);
- ora_oci_bind_int(p_sql_servicestatus, ":X31", &v31);
- ora_oci_bind_int(p_sql_servicestatus, ":X32", &v32);
- ora_oci_bind_int(p_sql_servicestatus, ":X33", &v33);
- ora_oci_bind_float(p_sql_servicestatus, ":X34", &v34);
- ora_oci_bind_float(p_sql_servicestatus, ":X35", &v35);
- ora_oci_bind_float(p_sql_servicestatus, ":X36", &v36);
- ora_oci_bind_int(p_sql_servicestatus, ":X37", &v37);
- ora_oci_bind_int(p_sql_servicestatus, ":X38", &v38);
- ora_oci_bind_int(p_sql_servicestatus, ":X39", &v39);
- ora_oci_bind_int(p_sql_servicestatus, ":X40", &v40);
- ora_oci_bind_long(p_sql_servicestatus, ":X41", &v41);
- ora_oci_bind_char(p_sql_servicestatus, ":X42", v42);
- ora_oci_bind_char(p_sql_servicestatus, ":X43", v43);
- ora_oci_bind_float(p_sql_servicestatus, ":X44", &v44);
- ora_oci_bind_float(p_sql_servicestatus, ":X45", &v45);
- ora_oci_bind_long(p_sql_servicestatus, ":X46", &v46);
+ int i;
+
+ i = bind_long(p_sql_servicestatus, ":X1", &v1);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_long(p_sql_servicestatus, ":X2", &v2);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_long(p_sql_servicestatus, ":X3", &v3);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_char(p_sql_servicestatus, ":X4", v4);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_char(p_sql_servicestatus, ":X5", v5);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_int(p_sql_servicestatus, ":X6", &v6);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_int(p_sql_servicestatus, ":X7", &v7);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_int(p_sql_servicestatus, ":X8", &v8);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_int(p_sql_servicestatus, ":X9", &v9);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_int(p_sql_servicestatus, ":X10", &v10);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_long(p_sql_servicestatus, ":X11", &v11);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_long(p_sql_servicestatus, ":X12", &v12);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_int(p_sql_servicestatus, ":X13", &v13);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_long(p_sql_servicestatus, ":X14", &v14);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_long(p_sql_servicestatus, ":X15", &v15);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_int(p_sql_servicestatus, ":X16", &v16);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_long(p_sql_servicestatus, ":X17", &v17);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_long(p_sql_servicestatus, ":X18", &v18);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_long(p_sql_servicestatus, ":X19", &v19);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_long(p_sql_servicestatus, ":X20", &v20);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_int(p_sql_servicestatus, ":X21", &v21);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_long(p_sql_servicestatus, ":X22", &v22);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_long(p_sql_servicestatus, ":X23", &v23);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_int(p_sql_servicestatus, ":X24", &v24);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_int(p_sql_servicestatus, ":X25", &v25);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_int(p_sql_servicestatus, ":X26", &v26);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_int(p_sql_servicestatus, ":X27", &v27);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_int(p_sql_servicestatus, ":X28", &v28);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_int(p_sql_servicestatus, ":X29", &v29);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_int(p_sql_servicestatus, ":X30", &v30);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_int(p_sql_servicestatus, ":X31", &v31);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_int(p_sql_servicestatus, ":X32", &v32);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_int(p_sql_servicestatus, ":X33", &v33);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_float(p_sql_servicestatus, ":X34", &v34);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_float(p_sql_servicestatus, ":X35", &v35);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_float(p_sql_servicestatus, ":X36", &v36);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_int(p_sql_servicestatus, ":X37", &v37);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_int(p_sql_servicestatus, ":X38", &v38);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_int(p_sql_servicestatus, ":X39", &v39);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_int(p_sql_servicestatus, ":X40", &v40);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_long(p_sql_servicestatus, ":X41", &v41);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_char(p_sql_servicestatus, ":X42", v42);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_char(p_sql_servicestatus, ":X43", v43);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_float(p_sql_servicestatus, ":X44", &v44);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_float(p_sql_servicestatus, ":X45", &v45);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_long(p_sql_servicestatus, ":X46", &v46);
+ if (i != OCI_SUCCESS)
+ return i;
rc = OCIStmtExecute(p_svc, p_sql_servicestatus, p_err, (ub4) 1,
(ub4) 0, (CONST OCISnapshot *) NULL,
(OCISnapshot *) NULL, OCI_COMMIT_ON_SUCCESS);
rc = checkerr(p_err, rc);
- if (rc != OCI_SUCCESS)
- return (-1);
- ndo2db_log
- ("MERGE INTO SERVICESTATUS Statement successfully executed.");
-
- return (0);
+ if (rc == OCI_SUCCESS)
+ ndo2db_log
+ ("MERGE INTO SERVICESTATUS Statement successfully executed.");
+ else
+ ndo2db_log
+ ("MERGE INTO SERVICESTATUS Statement failed: %s",
+ ora_oci_error());
+ return (rc);
}
-static int ora_oci_merge_servicechecks(unsigned long v1, char *v2, char *v3,
- unsigned long v4, unsigned long v5, int v6,
- int v7, int v8, int v9, int v10,
- unsigned long v11, unsigned long v12,
- unsigned long v13, unsigned long v14, int v15,
- int v16, float v17, float v18, int v19,
- char *v20, char *v21)
+static int merge_servicechecks(unsigned long v1, char *v2, char *v3,
+ unsigned long v4, unsigned long v5,
+ int v6, int v7, int v8, int v9,
+ int v10, unsigned long v11,
+ unsigned long v12, unsigned long v13,
+ unsigned long v14, int v15, int v16,
+ float v17, float v18, int v19,
+ char *v20, char *v21)
{
- ora_oci_bind_float(p_sql_servicechecks, ":X1", &v1);
- ora_oci_bind_char(p_sql_servicechecks, ":X2", v2);
- ora_oci_bind_char(p_sql_servicechecks, ":X3", v3);
- ora_oci_bind_int(p_sql_servicechecks, ":X4", &v4);
- ora_oci_bind_int(p_sql_servicechecks, ":X5", &v5);
- ora_oci_bind_int(p_sql_servicechecks, ":X6", &v6);
- ora_oci_bind_int(p_sql_servicechecks, ":X7", &v7);
- ora_oci_bind_int(p_sql_servicechecks, ":X8", &v8);
- ora_oci_bind_int(p_sql_servicechecks, ":X9", &v9);
- ora_oci_bind_int(p_sql_servicechecks, ":X10", &v10);
- ora_oci_bind_long(p_sql_servicechecks, ":X11", &v11);
- ora_oci_bind_int(p_sql_servicechecks, ":X12", &v12);
- ora_oci_bind_long(p_sql_servicechecks, ":X13", &v13);
- ora_oci_bind_int(p_sql_servicechecks, ":X14", &v14);
- ora_oci_bind_int(p_sql_servicechecks, ":X15", &v15);
- ora_oci_bind_int(p_sql_servicechecks, ":X16", &v16);
- ora_oci_bind_float(p_sql_servicechecks, ":X17", &v17);
- ora_oci_bind_float(p_sql_servicechecks, ":X18", &v18);
- ora_oci_bind_int(p_sql_servicechecks, ":X19", &v19);
- ora_oci_bind_char(p_sql_servicechecks, ":X20", v20);
- ora_oci_bind_char(p_sql_servicechecks, ":X21", v21);
+ int i;
+
+ i = bind_long(p_sql_servicechecks, ":X1", &v1);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_char(p_sql_servicechecks, ":X2", v2);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_char(p_sql_servicechecks, ":X3", v3);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_long(p_sql_servicechecks, ":X4", &v4);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_long(p_sql_servicechecks, ":X5", &v5);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_int(p_sql_servicechecks, ":X6", &v6);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_int(p_sql_servicechecks, ":X7", &v7);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_int(p_sql_servicechecks, ":X8", &v8);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_int(p_sql_servicechecks, ":X9", &v9);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_int(p_sql_servicechecks, ":X10", &v10);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_long(p_sql_servicechecks, ":X11", &v11);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_int(p_sql_servicechecks, ":X12", &v12);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_long(p_sql_servicechecks, ":X13", &v13);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_int(p_sql_servicechecks, ":X14", &v14);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_int(p_sql_servicechecks, ":X15", &v15);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_int(p_sql_servicechecks, ":X16", &v16);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_float(p_sql_servicechecks, ":X17", &v17);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_float(p_sql_servicechecks, ":X18", &v18);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_int(p_sql_servicechecks, ":X19", &v19);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_char(p_sql_servicechecks, ":X20", v20);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_char(p_sql_servicechecks, ":X21", v21);
+ if (i != OCI_SUCCESS)
+ return i;
rc = OCIStmtExecute(p_svc, p_sql_servicechecks, p_err, (ub4) 1,
(ub4) 0, (CONST OCISnapshot *) NULL,
(OCISnapshot *) NULL, OCI_COMMIT_ON_SUCCESS);
rc = checkerr(p_err, rc);
- if (rc != OCI_SUCCESS)
- return (-1);
- ndo2db_log
- ("MERGE INTO SERVICECHECKS Statement successfully executed.");
+ if (rc == OCI_SUCCESS)
+ ndo2db_log
+ ("MERGE INTO SERVICECHECKS Statement successfully executed.");
+ else
+ ndo2db_log
+ ("MERGE INTO SERVICECHECKS Statement failed: %s",
+ ora_oci_error());
- return (0);
+ return (rc);
}
+static int merge_contact_notifcmds(unsigned long v1, unsigned long v2, int v3,
+ unsigned long v4, char *v5)
+{
+ int i;
+
+ i = bind_long(p_sql_contact_notifcmds, ":X1", &v1);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_long(p_sql_contact_notifcmds, ":X2", &v2);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_int(p_sql_contact_notifcmds, ":X3", &v3);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_long(p_sql_contact_notifcmds, ":X4", &v4);
+ if (i != OCI_SUCCESS)
+ return i;
+ i = bind_char(p_sql_contact_notifcmds, ":X5", v5);
+ if (i != OCI_SUCCESS)
+ return i;
+
+ rc = OCIStmtExecute(p_svc, p_sql_contact_notifcmds, p_err, (ub4) 1,
+ (ub4) 0, (CONST OCISnapshot *) NULL,
+ (OCISnapshot *) NULL, OCI_COMMIT_ON_SUCCESS);
+ rc = checkerr(p_err, rc);
+ if (rc == OCI_SUCCESS)
+ ndo2db_log
+ ("MERGE INTO CONTACTNOTIFICATIONCOMMANDS Statement successfully executed.");
+ else
+ ndo2db_log
+ ("MERGE INTO CONTACTNOTIFICATIONCOMMANDS Statement failed: %s",
+ ora_oci_error());
+
+ return (rc);
+
+}
int ora_oci_query2(int type, void **data)
{
+ int ret = OCI_SUCCESS;
+
switch (type) {
case LIBOCI_MERGE_SERVICESTATUS:
- return ora_oci_merge_servicestatus(*(unsigned long *) data[0],
- *(unsigned long *) data[1],
- *(unsigned long *) data[2],
- *(char **) data[3],
- *(char **) data[4],
- *(int *) data[5],
- *(int *) data[6],
- *(int *) data[7],
- *(int *) data[8],
- *(int *) data[9],
- *(unsigned long *)
- data[10],
- *(unsigned long *)
- data[11],
- *(int *) data[12],
- *(unsigned long *)
- data[13],
- *(unsigned long *)
- data[14],
- *(int *) data[15],
- *(unsigned long *)
- data[16],
- *(unsigned long *)
- data[17],
- *(unsigned long *)
- data[18],
- *(unsigned long *)
- data[19],
- *(int *) data[20],
- *(unsigned long *)
- data[21],
- *(unsigned long *)
- data[22],
- *(int *) data[23],
- *(int *) data[24],
- *(int *) data[25],
- *(int *) data[26],
- *(int *) data[27],
- *(int *) data[28],
- *(int *) data[29],
- *(int *) data[30],
- *(int *) data[31],
- *(int *) data[32],
- *(float *) data[33],
- *(float *) data[34],
- *(float *) data[35],
- *(int *) data[36],
- *(int *) data[37],
- *(int *) data[38],
- *(int *) data[39],
- *(unsigned long *)
- data[40],
- *(char **) data[41],
- *(char **) data[42],
- *(float *) data[43],
- *(float *) data[44],
- *(unsigned long *) data[45]
+ ret = merge_servicestatus(*(unsigned long *) data[0],
+ *(unsigned long *) data[1],
+ *(unsigned long *) data[2],
+ *(char **) data[3],
+ *(char **) data[4],
+ *(int *) data[5],
+ *(int *) data[6],
+ *(int *) data[7],
+ *(int *) data[8],
+ *(int *) data[9],
+ *(unsigned long *) data[10],
+ *(unsigned long *) data[11],
+ *(int *) data[12],
+ *(unsigned long *) data[13],
+ *(unsigned long *) data[14],
+ *(int *) data[15],
+ *(unsigned long *) data[16],
+ *(unsigned long *) data[17],
+ *(unsigned long *) data[18],
+ *(unsigned long *) data[19],
+ *(int *) data[20],
+ *(unsigned long *) data[21],
+ *(unsigned long *) data[22],
+ *(int *) data[23],
+ *(int *) data[24],
+ *(int *) data[25],
+ *(int *) data[26],
+ *(int *) data[27],
+ *(int *) data[28],
+ *(int *) data[29],
+ *(int *) data[30],
+ *(int *) data[31],
+ *(int *) data[32],
+ *(float *) data[33],
+ *(float *) data[34],
+ *(float *) data[35],
+ *(int *) data[36],
+ *(int *) data[37],
+ *(int *) data[38],
+ *(int *) data[39],
+ *(unsigned long *) data[40],
+ *(char **) data[41],
+ *(char **) data[42],
+ *(float *) data[43],
+ *(float *) data[44],
+ *(unsigned long *) data[45]
);
break;
case LIBOCI_MERGE_SERVICECHECKS:
- printf("X11 = %d\n", *(int *) data[10]);
- return ora_oci_merge_servicechecks(*(float *) data[0],
- *(char **) data[1],
- *(char **) data[2],
- *(int *) data[3],
- *(int *) data[4],
- *(int *) data[5],
- *(int *) data[6],
- *(int *) data[7],
- *(int *) data[8],
- *(int *) data[9],
- *(unsigned long *)
- data[10],
- *(int *) data[11],
- *(unsigned long *)
- data[12],
- *(int *) data[13],
- *(int *) data[14],
- *(int *) data[15],
- *(float *) data[16],
- *(float *) data[17],
- *(int *) data[18],
- *(char **) data[19],
- *(char **) data[20]
+ ret = merge_servicechecks(*(unsigned long *) data[0],
+ *(char **) data[1],
+ *(char **) data[2],
+ *(unsigned long *) data[3],
+ *(unsigned long *) data[4],
+ *(int *) data[5],
+ *(int *) data[6],
+ *(int *) data[7],
+ *(int *) data[8],
+ *(int *) data[9],
+ *(unsigned long *) data[10],
+ *(int *) data[11],
+ *(unsigned long *) data[12],
+ *(int *) data[13],
+ *(int *) data[14],
+ *(int *) data[15],
+ *(float *) data[16],
+ *(float *) data[17],
+ *(int *) data[18],
+ *(char **) data[19],
+ *(char **) data[20]
);
break;
+ case LIBOCI_MERGE_CONTACT_NOTIFICATION_COMMANDS:
+ ret = merge_contact_notifcmds(*(unsigned long *) data[0],
+ *(unsigned long *) data[1],
+ *(int *) data[2],
+ *(unsigned long *) data[3],
+ *(char **) data[4]);
+ break;
default:
- sprintf(error_msg, "ERROR: Unknown Statement Type %d.", type);
- ndo2db_log(error_msg);
+ ndo2db_log("ERROR: Unknown Statement Type %d.", type);
return (-1);
}
+ return ret;
}
-
diff --git a/src/dbhandlers.c b/src/dbhandlers.c
index e5a144a..a82cdc7 100644
--- a/src/dbhandlers.c
+++ b/src/dbhandlers.c
@@ -1978,6 +1978,8 @@ int ndo2db_handle_servicecheckdata(ndo2db_idi *idi){
data[19] = (void *) &es[2];
data[20] = (void *) &es[3];
result = ndo2db_db_query2(idi, LIBOCI_MERGE_SERVICECHECKS, data);
+ if (result)
+ return NDO_ERROR;
#endif
/*
result=ndo2db_db_query(idi,buf);
@@ -3803,6 +3805,8 @@ int ndo2db_handle_servicestatusdata(ndo2db_idi *idi){
data[45] = (void *) &check_timeperiod_object_id;
result = ndo2db_db_query2(idi, LIBOCI_MERGE_SERVICESTATUS, data);
+ if (result)
+ return NDO_ERROR;
#endif
/* save entry to db */
@@ -7622,7 +7626,11 @@ int ndo2db_handle_contactdefinition(ndo2db_idi *idi){
)==-1)
buf=NULL;
free(buf1);
+
+ result=ndo2db_db_query(idi,buf);
+ free(buf);
#else
+# if 0
/* Unique constraint, upon match with these columns an UPDATE takes place, an INSERT otherwise */
if(asprintf(&buf1, "contact_id='%lu' AND notification_type='%d' AND command_object_id='%lu' AND command_args='%s'"
,contact_id
@@ -7658,11 +7666,19 @@ int ndo2db_handle_contactdefinition(ndo2db_idi *idi){
free(buf1);
free(buf2);
free(buf3);
+# else
+ void *data[5];
+ int notification_type = HOST_NOTIFICATION;
+ data[0] = (void *) &idi->dbinfo.instance_id;
+ data[1] = (void *) &contact_id;
+ data[2] = (void *) &notification_type;
+ data[3] = (void *) &command_id;
+ data[4] = (void *) &es[0];
+ result = ndo2db_db_query2(idi, LIBOCI_MERGE_CONTACT_NOTIFICATION_COMMANDS, data);
+ if (result)
+ return NDO_ERROR;
+# endif
#endif
-
- result=ndo2db_db_query(idi,buf);
- free(buf);
-
free(es[0]);
}
@@ -7700,7 +7716,11 @@ int ndo2db_handle_contactdefinition(ndo2db_idi *idi){
)==-1)
buf=NULL;
free(buf1);
+
+ result=ndo2db_db_query(idi,buf);
+ free(buf);
#else
+# if 0
/* Unique constraint, upon match with these columns an UPDATE takes place, an INSERT otherwise */
if(asprintf(&buf1, "contact_id='%lu' AND notification_type='%d' AND command_object_id='%lu' AND command_args='%s'"
,contact_id
@@ -7736,10 +7756,19 @@ int ndo2db_handle_contactdefinition(ndo2db_idi *idi){
free(buf1);
free(buf2);
free(buf3);
+# else
+ void *data[5];
+ int notification_type = SERVICE_NOTIFICATION;
+ data[0] = (void *) &idi->dbinfo.instance_id;
+ data[1] = (void *) &contact_id;
+ data[2] = (void *) &notification_type;
+ data[3] = (void *) &command_id;
+ data[4] = (void *) &es[0];
+ result = ndo2db_db_query2(idi, LIBOCI_MERGE_CONTACT_NOTIFICATION_COMMANDS, data);
+ if (result)
+ return NDO_ERROR;
+# endif
#endif
- result=ndo2db_db_query(idi,buf);
- free(buf);
-
free(es[0]);
}