+/*
+ * List running jobs for Bat or Bweb in a format
+ * simpler to parse. Be careful when changing this
+ * subroutine.
+ */
+static void list_running_jobs_api(STATUS_PKT *sp)
+{
+ OutputWriter ow(sp->api_opts);
+ int sec, bps;
+ char *p;
+ JCR *njcr;
+
+ /* API v1, edit with comma, space before the name, sometime ' ' as separator */
+
+ foreach_jcr(njcr) {
+ p = ow.get_output(OT_CLEAR, OT_START_OBJ, OT_END);
+
+ if (njcr->JobId == 0) {
+ ow.get_output(OT_UTIME, "DirectorConnected", njcr->start_time,
+ OT_INT, "DirTLS", (njcr->dir_bsock && njcr->dir_bsock->tls)?1:0,
+ OT_END);
+ } else {
+ ow.get_output(OT_INT32, "JobId", njcr->JobId,
+ OT_STRING, "Job", njcr->Job,
+ OT_JOBLEVEL,"Level", njcr->getJobLevel(),
+ OT_JOBTYPE, "Type", njcr->getJobType(),
+ OT_JOBSTATUS, "Status", njcr->getJobStatus(),
+ OT_UTIME, "StartTime", njcr->start_time,
+ OT_END);
+
+ }
+ sendit(p, strlen(p), sp);
+ if (njcr->JobId == 0) {
+ continue;
+ }
+ sec = time(NULL) - njcr->start_time;
+ if (sec <= 0) {
+ sec = 1;
+ }
+ bps = (int)(njcr->JobBytes / sec);
+ ow.get_output(OT_CLEAR,
+ OT_INT32, "JobFiles", njcr->JobFiles,
+ OT_SIZE, "JobBytes", njcr->JobBytes,
+ OT_INT, "Bytes/sec", bps,
+ OT_INT, "Errors", njcr->JobErrors,
+ OT_INT64, "Bwlimit", njcr->max_bandwidth,
+ OT_SIZE, "ReadBytes", njcr->ReadBytes,
+ OT_END);
+
+ ow.get_output(OT_INT32, "Files Examined", njcr->num_files_examined, OT_END);
+
+ if (njcr->is_JobType(JT_RESTORE) && njcr->ExpectedFiles > 0) {
+ ow.get_output(OT_INT32, "Expected Files", njcr->ExpectedFiles,
+ OT_INT32, "Percent Complete", 100*(njcr->num_files_examined/njcr->ExpectedFiles),
+ OT_END);
+ }
+
+ sendit(p, strlen(p), sp);
+ ow.get_output(OT_CLEAR, OT_END);
+
+ if (njcr->JobFiles > 0) {
+ njcr->lock();
+ ow.get_output(OT_STRING, "Processing file", njcr->last_fname, OT_END);
+ njcr->unlock();
+ }
+
+ if (njcr->store_bsock) {
+ ow.get_output(OT_INT64, "SDReadSeqNo", (int64_t)njcr->store_bsock->read_seqno,
+ OT_INT, "fd", njcr->store_bsock->m_fd,
+ OT_INT, "SDtls", (njcr->store_bsock->tls)?1:0,
+ OT_END);
+ } else {
+ ow.get_output(OT_STRING, "SDSocket", "closed", OT_END);
+ }
+ ow.get_output(OT_END_OBJ, OT_END);
+ sendit(p, strlen(p), sp);
+ }
+ endeach_jcr(njcr);
+}
+