*
* Nagios Plugin check_bacula
*
- * Christian Masopust, (c)2005
- *
- * Version $Id: check_bacula.c,v 1.0 2005/02/25
+ * Christian Masopust, (c)2005-2012
*/
/*
- Copyright (C) 2005 Christian Masopust
+ Copyright (C) 2005-2012 Christian Masopust
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
/*********************************************************************
*
- * Main Bacula Tray Monitor -- User Interface Program
+ * Main Bacula Tray Monitor -- User Interface Program
*
*/
int main(int argc, char *argv[])
switch (ch) {
- case 'H':
- strcpy (host, optarg);
- break;
-
- case 'D':
- strcpy (daemon, optarg);
- break;
-
- case 'M':
- strcpy (monitorname, optarg);
- break;
-
- case 'P':
- port = atoi(optarg);
- break;
-
- case 'K':
- strcpy (pw, optarg);
- break;
-
- case 'd':
- debug_level = atoi(optarg);
- if (debug_level <= 0) {
- debug_level = 1;
- }
- break;
-
- case 'h':
- case '?':
- default:
- usage();
- exit(1);
+ case 'H':
+ strcpy (host, optarg);
+ break;
+
+ case 'D':
+ strcpy (daemon, optarg);
+ break;
+
+ case 'M':
+ strcpy (monitorname, optarg);
+ break;
+
+ case 'P':
+ port = atoi(optarg);
+ break;
+
+ case 'K':
+ strcpy (pw, optarg);
+ break;
+
+ case 'd':
+ debug_level = atoi(optarg);
+ if (debug_level <= 0) {
+ debug_level = 1;
+ }
+ break;
+
+ case 'h':
+ case '?':
+ default:
+ usage();
+ exit(1);
}
}
argc -= optind;
/* director ? */
if (strcmp (daemon, "dir") == 0) {
- if (port != 0)
- s_dird.DIRport = port;
- else
- s_dird.DIRport = 9101;
+ if (port != 0)
+ s_dird.DIRport = port;
+ else
+ s_dird.DIRport = 9101;
- s_dird.address = host;
- s_dird.password = sig;
- s_dird.hdr.name = monitorname;
+ s_dird.address = host;
+ s_dird.password = sig;
+ s_dird.hdr.name = monitorname;
- mitem.type = R_DIRECTOR;
- mitem.resource = &s_dird;
- mitem.D_sock = NULL;
+ mitem.type = R_DIRECTOR;
+ mitem.resource = &s_dird;
+ mitem.D_sock = NULL;
} else if (strcmp (daemon, "sd") == 0) {
- if (port != 0)
- s_stored.SDport = port;
- else
- s_stored.SDport = 9103;
+ if (port != 0)
+ s_stored.SDport = port;
+ else
+ s_stored.SDport = 9103;
- s_stored.address = host;
- s_stored.password = sig;
- s_stored.hdr.name = monitorname;
+ s_stored.address = host;
+ s_stored.password = sig;
+ s_stored.hdr.name = monitorname;
- mitem.type = R_STORAGE;
- mitem.resource = &s_stored;
- mitem.D_sock = NULL;
+ mitem.type = R_STORAGE;
+ mitem.resource = &s_stored;
+ mitem.D_sock = NULL;
} else if (strcmp (daemon, "fd") == 0) {
- if (port != 0)
- s_filed.FDport = port;
- else
- s_filed.FDport = 9102;
+ if (port != 0)
+ s_filed.FDport = port;
+ else
+ s_filed.FDport = 9102;
- s_filed.address = host;
- s_filed.password = sig;
- s_filed.hdr.name = monitorname;
+ s_filed.address = host;
+ s_filed.password = sig;
+ s_filed.hdr.name = monitorname;
- mitem.type = R_CLIENT;
- mitem.resource = &s_filed;
- mitem.D_sock = NULL;
+ mitem.type = R_CLIENT;
+ mitem.resource = &s_filed;
+ mitem.D_sock = NULL;
} else {
- usage();
- exit(1);
+ usage();
+ exit(1);
}
if (mitem.type == R_DIRECTOR)
- retcode = docmd(&mitem, ".status dir current\n", answer);
+ retcode = docmd(&mitem, ".status dir current\n", answer);
else
- retcode = docmd(&mitem, ".status current\n", answer);
+ retcode = docmd(&mitem, ".status current\n", answer);
if (mitem.D_sock) {
- bnet_sig(mitem.D_sock, BNET_TERMINATE); /* send EOF */
- bnet_close(mitem.D_sock);
+ mitem.D_sock->signal(BNET_TERMINATE); /* send EOF */
+ mitem.D_sock->close();
}
printf ("%s\n", answer);
int stat;
char num;
const char *dname;
-
+
dname = "";
if (!item->D_sock) {
switch (item->type) {
case R_DIRECTOR:
- dird = (DIRRES*)item->resource;
- item->D_sock = bnet_connect(NULL, 0, 0, 0, "Director daemon", dird->address, NULL, dird->DIRport, 0);
- dname = "Director";
- break;
+ dird = (DIRRES*)item->resource;
+ item->D_sock = new_bsock();
+ item->D_sock->connect(NULL, 0, 0, 0, "Director daemon", dird->address, NULL, dird->DIRport, 0);
+ dname = "Director";
+ break;
case R_CLIENT:
- filed = (CLIENT*)item->resource;
- item->D_sock = bnet_connect(NULL, 0, 0, 0, "File daemon", filed->address, NULL, filed->FDport, 0);
- dname = "FileDaemon";
- break;
+ filed = (CLIENT*)item->resource;
+ item->D_sock = new_bsock();
+ item->D_sock = connect(NULL, 0, 0, 0, "File daemon", filed->address, NULL, filed->FDport, 0);
+ dname = "FileDaemon";
+ break;
case R_STORAGE:
- stored = (STORE*)item->resource;
- item->D_sock = bnet_connect(NULL, 0, 0, 0, "Storage daemon", stored->address, NULL, stored->SDport, 0);
- dname = "StorageDaemon";
- break;
+ stored = (STORE*)item->resource;
+ item->D_sock = new_bsock();
+ item->D_sock->connect(NULL, 0, 0, 0, "Storage daemon", stored->address, NULL, stored->SDport, 0);
+ dname = "StorageDaemon";
+ break;
default:
- printf("Error, currentitem is not a Client, a Storage or a Director..\n");
- return STATE_UNKNOWN;
+ printf("Error, currentitem is not a Client, a Storage or a Director..\n");
+ return STATE_UNKNOWN;
}
if (item->D_sock == NULL) {
- sprintf (answer, "BACULA CRITICAL - Cannot connect to %s!", dname);
- return STATE_CRITICAL;
+ sprintf (answer, "BACULA CRITICAL - Cannot connect to %s!", dname);
+ return STATE_CRITICAL;
}
if (!authenticate_daemon(item)) {
- sprintf (answer, "BACULA CRITICAL - Cannot authenticate to %s: %s", dname, item->D_sock->msg);
- item->D_sock = NULL;
- return STATE_CRITICAL;
+ sprintf (answer, "BACULA CRITICAL - Cannot authenticate to %s: %s", dname, item->D_sock->msg);
+ item->D_sock = NULL;
+ return STATE_CRITICAL;
}
}
writecmd(item, command);
while(1) {
- if ((stat = bnet_recv(item->D_sock)) >= 0) {
-
- /* welcome message of director */
- if ((item->type == R_DIRECTOR) && (strncmp(item->D_sock->msg, "Using ", 6) == 0))
- continue;
-
- if (sscanf(item->D_sock->msg, OKqstatus, &num) != 1) {
- /* Error, couldn't find OK */
- sprintf (answer, "BACULA CRITICAL - %s Status: %s", dname, item->D_sock->msg);
- return STATE_CRITICAL;
- } else {
- sprintf (answer, "BACULA OK - %s Status OK", dname);
- return STATE_OK;
- }
+ if ((stat = item->D_sock->recv()) >= 0) {
+
+ /* welcome message of director */
+ if ((item->type == R_DIRECTOR) && (strncmp(item->D_sock->msg, "Using ", 6) == 0))
+ continue;
+
+ if (sscanf(item->D_sock->msg, OKqstatus, &num) != 1) {
+ /* Error, couldn't find OK */
+ sprintf (answer, "BACULA CRITICAL - %s Status: %s", dname, item->D_sock->msg);
+ return STATE_CRITICAL;
+ } else {
+ sprintf (answer, "BACULA OK - %s Status OK", dname);
+ return STATE_OK;
+ }
}
else if (stat == BNET_SIGNAL) {
- if (item->D_sock->msglen == BNET_EOD) {
- strcpy(answer, "BACULA WARNING - << EOD >>");
- return STATE_WARNING;
- }
- else if (item->D_sock->msglen == BNET_SUB_PROMPT) {
- strcpy(answer, "BACULA WARNING - BNET_SUB_PROMPT signal received.");
- return STATE_WARNING;
- }
- else if (item->D_sock->msglen == BNET_HEARTBEAT) {
- bnet_sig(item->D_sock, BNET_HB_RESPONSE);
- }
- else {
- sprintf(answer, "BACULA WARNING - Unexpected signal received : %s ", bnet_sig_to_ascii(item->D_sock));
- }
+ if (item->D_sock->msglen == BNET_EOD) {
+ strcpy(answer, "BACULA WARNING - << EOD >>");
+ return STATE_WARNING;
+ }
+ else if (item->D_sock->msglen == BNET_SUB_PROMPT) {
+ strcpy(answer, "BACULA WARNING - BNET_SUB_PROMPT signal received.");
+ return STATE_WARNING;
+ }
+ else if (item->D_sock->msglen == BNET_HEARTBEAT) {
+ item->D_sock->signal(BNET_HB_RESPONSE);
+ }
+ else {
+ sprintf(answer, "BACULA WARNING - Unexpected signal received : %s ", bnet_sig_to_ascii(item->D_sock));
+ }
}
else { /* BNET_HARDEOF || BNET_ERROR */
- strcpy(answer, "BACULA CRITICAL - ERROR: BNET_HARDEOF or BNET_ERROR");
- item->D_sock = NULL;
- return STATE_CRITICAL;
+ strcpy(answer, "BACULA CRITICAL - ERROR: BNET_HARDEOF or BNET_ERROR");
+ item->D_sock = NULL;
+ return STATE_CRITICAL;
}
- if (is_bnet_stop(item->D_sock)) {
- item->D_sock = NULL;
- return STATE_WARNING;
+ if (item->D_sock->is_stop()) {
+ item->D_sock = NULL;
+ return STATE_WARNING;
}
}
}
if (item->D_sock) {
item->D_sock->msglen = strlen(command);
pm_strcpy(&item->D_sock->msg, command);
- bnet_send(item->D_sock);
+ item->D_sock->send();
}
}
-