コード例 #1
0
ファイル: sd_cmds.c プロジェクト: engeenity/bareos
/*
 * Establish a connection with the Storage daemon and perform authentication.
 */
bool connect_to_storage_daemon(JCR *jcr, int retry_interval,
                               int max_retry_time, bool verbose)
{
   BSOCK *sd = new_bsock();
   STORERES *store;
   utime_t heart_beat;

   if (jcr->store_bsock) {
      return true;                    /* already connected */
   }

   /*
    * If there is a write storage use it
    */
   if (jcr->res.wstore) {
      store = jcr->res.wstore;
   } else {
      store = jcr->res.rstore;
   }

   if (store->heartbeat_interval) {
      heart_beat = store->heartbeat_interval;
   } else {
      heart_beat = me->heartbeat_interval;
   }

   /*
    * Open message channel with the Storage daemon
    */
   Dmsg2(100, "bnet_connect to Storage daemon %s:%d\n", store->address, store->SDport);
   sd->set_source_address(me->DIRsrc_addr);
   if (!sd->connect(jcr, retry_interval, max_retry_time, heart_beat, _("Storage daemon"),
                    store->address, NULL, store->SDport, verbose)) {
      sd->destroy();
      sd = NULL;
   }

   if (sd == NULL) {
      return false;
   }
   sd->res = (RES *)store;        /* save pointer to other end */
   jcr->store_bsock = sd;

   if (!authenticate_storage_daemon(jcr, store)) {
      sd->close();
      jcr->store_bsock = NULL;
      return false;
   }

   return true;
}
コード例 #2
0
ファイル: check_bacula.c プロジェクト: rkorzeniewski/bacula
int docmd(monitoritem* item, const char* command, char *answer) {

   int stat;
   char num;
   const char *dname;

   dname = "";

   if (!item->D_sock) {

      DIRRES* dird;
      CLIENT* filed;
      STORE* stored;

      switch (item->type) {
      case R_DIRECTOR:
                 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 = 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 = 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;
      }

      if (item->D_sock == NULL) {
                 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;
      }

   }

   if (command[0] != 0)
      writecmd(item, command);

   while(1) {
      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) {
            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;
      }

      if (item->D_sock->is_stop()) {
                 item->D_sock = NULL;
                 return STATE_WARNING;
      }
   }
}