+
+/*
+ * .status command from Director
+ */
+bool qstatus_cmd(JCR *jcr)
+{
+ BSOCK *dir = jcr->dir_bsock;
+ POOL_MEM cmd;
+ JCR *njcr;
+ s_last_job* job;
+ STATUS_PKT sp;
+
+ sp.bs = dir;
+ if (sscanf(dir->msg, qstatus, cmd.c_str()) != 1) {
+ pm_strcpy(jcr->errmsg, dir->msg);
+ Jmsg1(jcr, M_FATAL, 0, _("Bad .status command: %s\n"), jcr->errmsg);
+ dir->fsend(_("3900 Bad .status command, missing argument.\n"));
+ dir->signal(BNET_EOD);
+ return false;
+ }
+ unbash_spaces(cmd);
+
+ Dmsg1(200, "cmd=%s\n", cmd.c_str());
+
+ if (strcmp(cmd.c_str(), "current") == 0) {
+ dir->fsend(OKqstatus, cmd.c_str());
+ foreach_jcr(njcr) {
+ if (njcr->JobId != 0) {
+ dir->fsend(DotStatusJob, njcr->JobId, njcr->JobStatus, njcr->JobErrors);
+ }
+ }
+ endeach_jcr(njcr);
+ } else if (strcmp(cmd.c_str(), "last") == 0) {
+ dir->fsend(OKqstatus, cmd.c_str());
+ if ((last_jobs) && (last_jobs->size() > 0)) {
+ job = (s_last_job*)last_jobs->last();
+ dir->fsend(DotStatusJob, job->JobId, job->JobStatus, job->Errors);
+ }
+ } else if (strcasecmp(cmd.c_str(), "header") == 0) {
+ sp.api = true;
+ list_status_header(&sp);
+ } else if (strcasecmp(cmd.c_str(), "running") == 0) {
+ sp.api = true;
+ list_running_jobs(&sp);
+ } else if (strcasecmp(cmd.c_str(), "waitreservation") == 0) {
+ sp.api = true;
+ list_jobs_waiting_on_reservation(&sp);
+ } else if (strcasecmp(cmd.c_str(), "devices") == 0) {
+ sp.api = true;
+ list_devices(&sp);
+ } else if (strcasecmp(cmd.c_str(), "volumes") == 0) {
+ sp.api = true;
+ list_volumes(sendit, &sp);
+ } else if (strcasecmp(cmd.c_str(), "spooling") == 0) {
+ sp.api = true;
+ list_spool_stats(sendit, &sp);
+ } else if (strcasecmp(cmd.c_str(), "terminated") == 0) {
+ sp.api = true;
+ list_terminated_jobs(&sp);
+ } else {
+ pm_strcpy(jcr->errmsg, dir->msg);
+ Jmsg1(jcr, M_FATAL, 0, _("Bad .status command: %s\n"), jcr->errmsg);
+ dir->fsend(_("3900 Bad .status command, wrong argument.\n"));
+ dir->signal(BNET_EOD);
+ return false;
+ }
+ dir->signal(BNET_EOD);
+ return true;
+}
+
+#if defined(HAVE_WIN32)
+int bacstat = 0;
+
+/* Return a one line status for the tray monitor */
+char *bac_status(char *buf, int buf_len)
+{
+ JCR *njcr;
+ const char *termstat = _("Bacula Storage: Idle");
+ struct s_last_job *job;
+ int stat = 0; /* Idle */
+
+ if (!last_jobs) {
+ goto done;
+ }
+ Dmsg0(1000, "Begin bac_status jcr loop.\n");
+ foreach_jcr(njcr) {
+ if (njcr->JobId != 0) {
+ stat = JS_Running;
+ termstat = _("Bacula Storage: Running");
+ break;
+ }
+ }
+ endeach_jcr(njcr);
+
+ if (stat != 0) {
+ goto done;
+ }
+ if (last_jobs->size() > 0) {
+ job = (struct s_last_job *)last_jobs->last();
+ stat = job->JobStatus;
+ switch (job->JobStatus) {
+ case JS_Canceled:
+ termstat = _("Bacula Storage: Last Job Canceled");
+ break;
+ case JS_ErrorTerminated:
+ case JS_FatalError:
+ termstat = _("Bacula Storage: Last Job Failed");
+ break;
+ default:
+ if (job->Errors) {
+ termstat = _("Bacula Storage: Last Job had Warnings");
+ }
+ break;
+ }
+ }
+ Dmsg0(1000, "End bac_status jcr loop.\n");
+done:
+ bacstat = stat;
+ if (buf) {
+ bstrncpy(buf, termstat, buf_len);
+ }
+ return buf;
+}
+
+#endif /* HAVE_WIN32 */