From: Kern Sibbald Date: Sun, 30 Mar 2014 14:03:40 +0000 (+0200) Subject: Attempt to fix nagios to use new bsock calls X-Git-Tag: Release-7.0.1~17 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=1f825e8e1bcec307befe21b8954e531624f758cd;p=bacula%2Fbacula Attempt to fix nagios to use new bsock calls --- diff --git a/bacula/examples/nagios/check_bacula/authenticate.c b/bacula/examples/nagios/check_bacula/authenticate.c index 94937b7719..0eb1c8f37c 100644 --- a/bacula/examples/nagios/check_bacula/authenticate.c +++ b/bacula/examples/nagios/check_bacula/authenticate.c @@ -76,7 +76,7 @@ int authenticate_director(BSOCK *dir, char *dirname, char *password) /* Timeout Hello after 5 mins */ btimer_t *tid = start_bsock_timer(dir, 60 * 5); - bnet_fsend(dir, DIRhello, bashed_name); + dir->fsend(DIRhello, bashed_name); if (!cram_md5_respond(dir, password, &tls_remote_need, &compatible) || !cram_md5_challenge(dir, password, tls_local_need, compatible)) { @@ -85,7 +85,7 @@ int authenticate_director(BSOCK *dir, char *dirname, char *password) } Dmsg1(6, ">dird: %s", dir->msg); - if (bnet_recv(dir) <= 0) { + if (dir->recv() <= 0) { stop_bsock_timer(tid); return 0; } @@ -114,7 +114,7 @@ int authenticate_storage_daemon(BSOCK *sd, char *sdname, char* password) bash_spaces(dirname); /* Timeout Hello after 5 mins */ btimer_t *tid = start_bsock_timer(sd, 60 * 5); - if (!bnet_fsend(sd, SDFDhello, dirname)) { + if (!sd->fsend(SDFDhello, dirname)) { stop_bsock_timer(tid); return 0; } @@ -124,7 +124,7 @@ int authenticate_storage_daemon(BSOCK *sd, char *sdname, char* password) return 0; } Dmsg1(116, ">stored: %s", sd->msg); - if (bnet_recv(sd) <= 0) { + if (sd->recv() <= 0) { stop_bsock_timer(tid); return 0; } @@ -153,7 +153,7 @@ int authenticate_file_daemon(BSOCK *fd, char *fdname, char *password) bash_spaces(dirname); /* Timeout Hello after 5 mins */ btimer_t *tid = start_bsock_timer(fd, 60 * 5); - if (!bnet_fsend(fd, SDFDhello, dirname)) { + if (!fd->fsend(SDFDhello, dirname)) { stop_bsock_timer(tid); return 0; } @@ -163,7 +163,7 @@ int authenticate_file_daemon(BSOCK *fd, char *fdname, char *password) return 0; } Dmsg1(116, ">filed: %s", fd->msg); - if (bnet_recv(fd) <= 0) { + if (fd->recv() <= 0) { stop_bsock_timer(tid); return 0; } diff --git a/bacula/examples/nagios/check_bacula/check_bacula.c b/bacula/examples/nagios/check_bacula/check_bacula.c index 58d6997b86..0aedfcd5f6 100644 --- a/bacula/examples/nagios/check_bacula/check_bacula.c +++ b/bacula/examples/nagios/check_bacula/check_bacula.c @@ -2,13 +2,11 @@ * * 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 @@ -73,7 +71,7 @@ static void usage() /********************************************************************* * - * Main Bacula Tray Monitor -- User Interface Program + * Main Bacula Tray Monitor -- User Interface Program * */ int main(int argc, char *argv[]) @@ -114,38 +112,38 @@ 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; @@ -171,65 +169,65 @@ int main(int argc, char *argv[]) /* 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); @@ -269,7 +267,7 @@ int docmd(monitoritem* item, const char* command, char *answer) { int stat; char num; const char *dname; - + dname = ""; if (!item->D_sock) { @@ -280,34 +278,37 @@ int docmd(monitoritem* item, const char* command, char *answer) { 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; } } @@ -316,46 +317,46 @@ int docmd(monitoritem* item, const char* command, char *answer) { 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; } } } @@ -364,7 +365,6 @@ void writecmd(monitoritem* item, const char* command) { 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(); } } -