static void list_scheduled_jobs(UAContext *ua);
static void list_running_jobs(UAContext *ua);
static void list_terminated_jobs(UAContext *ua);
-static void do_storage_status(UAContext *ua, STORE *store);
-static void do_client_status(UAContext *ua, CLIENT *client);
+static void do_storage_status(UAContext *ua, STORE *store, char *cmd);
+static void do_client_status(UAContext *ua, CLIENT *client, char *cmd);
static void do_director_status(UAContext *ua);
static void do_all_status(UAContext *ua);
bool dot_status_cmd(UAContext *ua, const char *cmd)
{
+ STORE *store;
+ CLIENT *client;
JCR* njcr = NULL;
s_last_job* job;
char ed1[50];
- Dmsg1(20, "status:%s:\n", cmd);
+ Dmsg2(20, "status=\"%s\" argc=%d\n", cmd, ua->argc);
- if ((ua->argc != 3) || (strcasecmp(ua->argk[1], "dir"))) {
+ if (ua->argc < 3) {
ua->send_msg("1900 Bad .status command, missing arguments.\n");
return false;
}
- if (strcasecmp(ua->argk[2], "current") == 0) {
- ua->send_msg(OKqstatus, ua->argk[2]);
- foreach_jcr(njcr) {
- if (njcr->JobId != 0 && acl_access_ok(ua, Job_ACL, njcr->job->name())) {
- ua->send_msg(DotStatusJob, edit_int64(njcr->JobId, ed1),
- njcr->JobStatus, njcr->JobErrors);
+ if (strcasecmp(ua->argk[1], "dir") == 0) {
+ if (strcasecmp(ua->argk[2], "current") == 0) {
+ ua->send_msg(OKqstatus, ua->argk[2]);
+ foreach_jcr(njcr) {
+ if (njcr->JobId != 0 && acl_access_ok(ua, Job_ACL, njcr->job->name())) {
+ ua->send_msg(DotStatusJob, edit_int64(njcr->JobId, ed1),
+ njcr->JobStatus, njcr->JobErrors);
+ }
}
- }
- endeach_jcr(njcr);
- } else if (strcasecmp(ua->argk[2], "last") == 0) {
- ua->send_msg(OKqstatus, ua->argk[2]);
- if ((last_jobs) && (last_jobs->size() > 0)) {
- job = (s_last_job*)last_jobs->last();
- if (acl_access_ok(ua, Job_ACL, job->Job)) {
- ua->send_msg(DotStatusJob, edit_int64(job->JobId, ed1),
- job->JobStatus, job->Errors);
+ endeach_jcr(njcr);
+ } else if (strcasecmp(ua->argk[2], "last") == 0) {
+ ua->send_msg(OKqstatus, ua->argk[2]);
+ if ((last_jobs) && (last_jobs->size() > 0)) {
+ job = (s_last_job*)last_jobs->last();
+ if (acl_access_ok(ua, Job_ACL, job->Job)) {
+ ua->send_msg(DotStatusJob, edit_int64(job->JobId, ed1),
+ job->JobStatus, job->Errors);
+ }
}
+ } else if (strcasecmp(ua->argk[2], "header") == 0) {
+ list_dir_status_header(ua);
+ } else if (strcasecmp(ua->argk[2], "scheduled") == 0) {
+ list_scheduled_jobs(ua);
+ } else if (strcasecmp(ua->argk[2], "running") == 0) {
+ list_running_jobs(ua);
+ } else if (strcasecmp(ua->argk[2], "terminated") == 0) {
+ list_terminated_jobs(ua);
+ } else {
+ ua->send_msg("1900 Bad .status command, wrong argument.\n");
+ return false;
+ }
+ } else if (strcasecmp(ua->argk[1], "client") == 0) {
+ client = get_client_resource(ua);
+ if (client) {
+ Dmsg2(000, "Client=%s arg=%s\n", client->name(), NPRT(ua->argk[2]));
+ do_client_status(ua, client, ua->argk[2]);
+ }
+ } else if (strcasecmp(ua->argk[1], "storage") == 0) {
+ store = get_storage_resource(ua, false /*no default*/);
+ if (store) {
+ do_storage_status(ua, store, ua->argk[2]);
}
- } else if (strcasecmp(ua->argk[2], "header") == 0) {
- list_dir_status_header(ua);
- } else if (strcasecmp(ua->argk[2], "scheduled") == 0) {
- list_scheduled_jobs(ua);
- } else if (strcasecmp(ua->argk[2], "running") == 0) {
- list_running_jobs(ua);
- } else if (strcasecmp(ua->argk[2], "terminated") == 0) {
- list_terminated_jobs(ua);
} else {
ua->send_msg("1900 Bad .status command, wrong argument.\n");
return false;
} else if (strcasecmp(ua->argk[i], NT_("client")) == 0) {
client = get_client_resource(ua);
if (client) {
- do_client_status(ua, client);
+ do_client_status(ua, client, NULL);
}
return 1;
} else {
store = get_storage_resource(ua, false/*no default*/);
if (store) {
- do_storage_status(ua, store);
+ do_storage_status(ua, store, NULL);
}
return 1;
}
case 1:
store = select_storage_resource(ua);
if (store) {
- do_storage_status(ua, store);
+ do_storage_status(ua, store, NULL);
}
break;
case 2:
client = select_client_resource(ua);
if (client) {
- do_client_status(ua, client);
+ do_client_status(ua, client, NULL);
}
break;
case 3:
/* Call each unique Storage daemon */
for (j=0; j<i; j++) {
- do_storage_status(ua, unique_store[j]);
+ do_storage_status(ua, unique_store[j], NULL);
}
free(unique_store);
/* Call each unique File daemon */
for (j=0; j<i; j++) {
- do_client_status(ua, unique_client[j]);
+ do_client_status(ua, unique_client[j], NULL);
}
free(unique_client);
ua->send_msg("====\n");
}
-static void do_storage_status(UAContext *ua, STORE *store)
+static void do_storage_status(UAContext *ua, STORE *store, char *cmd)
{
BSOCK *sd;
USTORE lstore;
pm_strcpy(lstore.store_source, _("unknown source"));
set_wstorage(ua->jcr, &lstore);
/* Try connecting for up to 15 seconds */
- ua->send_msg(_("Connecting to Storage daemon %s at %s:%d\n"),
+ if (!ua->api) ua->send_msg(_("Connecting to Storage daemon %s at %s:%d\n"),
store->name(), store->address, store->SDport);
if (!connect_to_storage_daemon(ua->jcr, 1, 15, 0)) {
ua->send_msg(_("\nFailed to connect to Storage daemon %s.\n====\n"),
}
Dmsg0(20, _("Connected to storage daemon\n"));
sd = ua->jcr->store_bsock;
- bnet_fsend(sd, "status");
- while (bnet_recv(sd) >= 0) {
+ if (cmd) {
+ sd->fsend(".status %s", cmd);
+ } else {
+ sd->fsend("status");
+ }
+ while (sd->recv() >= 0) {
ua->send_msg("%s", sd->msg);
}
- bnet_sig(sd, BNET_TERMINATE);
- bnet_close(sd);
+ sd->signal( BNET_TERMINATE);
+ sd->close();
ua->jcr->store_bsock = NULL;
return;
}
-static void do_client_status(UAContext *ua, CLIENT *client)
+static void do_client_status(UAContext *ua, CLIENT *client, char *cmd)
{
BSOCK *fd;
ua->jcr->sd_auth_key = bstrdup("dummy");
/* Try to connect for 15 seconds */
- ua->send_msg(_("Connecting to Client %s at %s:%d\n"),
+ if (!ua->api) ua->send_msg(_("Connecting to Client %s at %s:%d\n"),
client->name(), client->address, client->FDport);
if (!connect_to_file_daemon(ua->jcr, 1, 15, 0)) {
ua->send_msg(_("Failed to connect to Client %s.\n====\n"),
}
Dmsg0(20, _("Connected to file daemon\n"));
fd = ua->jcr->file_bsock;
- fd->fsend("status");
+ if (cmd) {
+ fd->fsend(".status %s", cmd);
+ } else {
+ fd->fsend("status");
+ }
while (fd->recv() >= 0) {
ua->send_msg("%s", fd->msg);
}
/*
Bacula® - The Network Backup Solution
- Copyright (C) 2001-2007 Free Software Foundation Europe e.V.
+ Copyright (C) 2001-2008 Free Software Foundation Europe e.V.
The main author of Bacula is Kern Sibbald, with contributions from
many others, a complete list can be found in the file AUTHORS.
extern void *start_heap;
/* Forward referenced functions */
-static void list_terminated_jobs(void sendit(const char *msg, int len, void *sarg), void *arg);
+static void list_terminated_jobs(void sendit(const char *msg, int len, void *sarg), void *arg, bool api);
+static void list_running_jobs(void sendit(const char *msg, int len, void *sarg), void *arg, bool api);
+static void list_status_header(void sendit(const char *msg, int len, void *sarg), void *arg, bool api);
static void bsock_sendit(const char *msg, int len, void *arg);
static const char *level_to_str(int level);
*/
void output_status(void sendit(const char *msg, int len, void *sarg), void *arg)
{
- int sec, bps;
+ list_status_header(sendit, arg, false /*no api*/);
+ list_running_jobs(sendit, arg, false /*no api*/);
+ list_terminated_jobs(sendit, arg, false /*no api*/);
+}
+
+static void list_status_header(void sendit(const char *msg, int len, void *sarg), void *arg, bool api)
+{
POOL_MEM msg(PM_MESSAGE);
char b1[32], b2[32], b3[32], b4[32], b5[35];
int len;
- bool found = false;
- JCR *njcr;
char dt[MAX_TIME_LENGTH];
len = Mmsg(msg, _("%s Version: %s (%s) %s %s %s %s\n"),
len = Mmsg(msg, _(" Sizeof: boffset_t=%d size_t=%d debug=%d trace=%d\n"),
sizeof(boffset_t), sizeof(size_t), debug_level, get_trace());
sendit(msg.c_str(), len, arg);
+}
+static void list_running_jobs(void sendit(const char *msg, int len, void *sarg), void *arg, bool api)
+{
+ int sec, bps;
+ POOL_MEM msg(PM_MESSAGE);
+ char b1[32], b2[32], b3[32];
+ int len;
+ bool found = false;
+ JCR *njcr;
+ char dt[MAX_TIME_LENGTH];
/*
* List running jobs
*/
Dmsg0(1000, "Begin status jcr loop.\n");
- len = Mmsg(msg, _("\nRunning Jobs:\n"));
- sendit(msg.c_str(), len, arg);
+ if (!api) {
+ len = Mmsg(msg, _("\nRunning Jobs:\n"));
+ sendit(msg.c_str(), len, arg);
+ }
const char *vss = "";
#ifdef WIN32_VSS
if (g_pVSSClient && g_pVSSClient->IsInitialized()) {
}
endeach_jcr(njcr);
- if (!found) {
- len = Mmsg(msg, _("No Jobs running.\n"));
- sendit(msg.c_str(), len, arg);
+ if (!api) {
+ if (!found) {
+ len = Mmsg(msg, _("No Jobs running.\n"));
+ sendit(msg.c_str(), len, arg);
+ }
+ sendit(_("====\n"), 5, arg);
}
- sendit(_("====\n"), 5, arg);
-
- list_terminated_jobs(sendit, arg);
}
+
-static void list_terminated_jobs(void sendit(const char *msg, int len, void *sarg), void *arg)
+static void list_terminated_jobs(void sendit(const char *msg, int len, void *sarg), void *arg, bool api)
{
char dt[MAX_TIME_LENGTH], b1[30], b2[30];
char level[10];
struct s_last_job *je;
const char *msg;
- msg = _("\nTerminated Jobs:\n");
- sendit(msg, strlen(msg), arg);
+ if (!api) {
+ msg = _("\nTerminated Jobs:\n");
+ sendit(msg, strlen(msg), arg);
+ }
if (last_jobs->size() == 0) {
- sendit(_("====\n"), 5, arg);
+ if (!api) sendit(_("====\n"), 5, arg);
return;
}
lock_last_jobs_list();
- msg = _(" JobId Level Files Bytes Status Finished Name \n");
- sendit(msg, strlen(msg), arg);
- msg = _("======================================================================\n");
- sendit(msg, strlen(msg), arg);
+ if (!api) {
+ msg = _(" JobId Level Files Bytes Status Finished Name \n");
+ sendit(msg, strlen(msg), arg);
+ msg = _("======================================================================\n");
+ sendit(msg, strlen(msg), arg);
+ }
foreach_dlist(je, last_jobs) {
char JobName[MAX_NAME_LENGTH];
const char *termstat;
*p = 0;
}
}
- bsnprintf(buf, sizeof(buf), _("%6d %-6s %8s %10s %-7s %-8s %s\n"),
- je->JobId,
- level,
- edit_uint64_with_commas(je->JobFiles, b1),
- edit_uint64_with_suffix(je->JobBytes, b2),
- termstat,
- dt, JobName);
+ if (api) {
+ bsnprintf(buf, sizeof(buf), _("%6d\t%-6s\t%8s\t%10s\t%-7s\t%-8s\t%s\n"),
+ je->JobId,
+ level,
+ edit_uint64_with_commas(je->JobFiles, b1),
+ edit_uint64_with_suffix(je->JobBytes, b2),
+ termstat,
+ dt, JobName);
+ } else {
+ bsnprintf(buf, sizeof(buf), _("%6d %-6s %8s %10s %-7s %-8s %s\n"),
+ je->JobId,
+ level,
+ edit_uint64_with_commas(je->JobFiles, b1),
+ edit_uint64_with_suffix(je->JobBytes, b2),
+ termstat,
+ dt, JobName);
+ }
sendit(buf, strlen(buf), arg);
}
- sendit(_("====\n"), 5, arg);
+ if (!api) sendit(_("====\n"), 5, arg);
unlock_last_jobs_list();
}
user->msg = check_pool_memory_size(user->msg, len+1);
memcpy(user->msg, msg, len+1);
user->msglen = len+1;
- bnet_send(user);
+ user->send();
}
/*
{
BSOCK *user = jcr->dir_bsock;
- bnet_fsend(user, "\n");
+ user->fsend("\n");
output_status(bsock_sendit, (void *)user);
- bnet_sig(user, BNET_EOD);
+ user->signal(BNET_EOD);
return 1;
}
int qstatus_cmd(JCR *jcr)
{
BSOCK *dir = jcr->dir_bsock;
- POOLMEM *time;
+ POOLMEM *cmd;
JCR *njcr;
s_last_job* job;
- time = get_memory(dir->msglen+1);
+ cmd = get_memory(dir->msglen+1);
- if (sscanf(dir->msg, qstatus, time) != 1) {
+ if (sscanf(dir->msg, qstatus, cmd) != 1) {
pm_strcpy(&jcr->errmsg, dir->msg);
Jmsg1(jcr, M_FATAL, 0, _("Bad .status command: %s\n"), jcr->errmsg);
- bnet_fsend(dir, _("2900 Bad .status command, missing argument.\n"));
- bnet_sig(dir, BNET_EOD);
- free_memory(time);
+ dir->fsend(_("2900 Bad .status command, missing argument.\n"));
+ dir->signal(BNET_EOD);
+ free_memory(cmd);
return 0;
}
- unbash_spaces(time);
+ unbash_spaces(cmd);
- if (strcmp(time, "current") == 0) {
- bnet_fsend(dir, OKqstatus, time);
+ if (strcmp(cmd, "current") == 0) {
+ dir->fsend(OKqstatus, cmd);
foreach_jcr(njcr) {
if (njcr->JobId != 0) {
- bnet_fsend(dir, DotStatusJob, njcr->JobId, njcr->JobStatus, njcr->JobErrors);
+ dir->fsend(DotStatusJob, njcr->JobId, njcr->JobStatus, njcr->JobErrors);
}
}
endeach_jcr(njcr);
- } else if (strcmp(time, "last") == 0) {
- bnet_fsend(dir, OKqstatus, time);
+ } else if (strcmp(cmd, "last") == 0) {
+ dir->fsend(OKqstatus, cmd);
if ((last_jobs) && (last_jobs->size() > 0)) {
job = (s_last_job*)last_jobs->last();
- bnet_fsend(dir, DotStatusJob, job->JobId, job->JobStatus, job->Errors);
+ dir->fsend(DotStatusJob, job->JobId, job->JobStatus, job->Errors);
}
+ } else if (strcasecmp(cmd, "header") == 0) {
+ list_status_header(bsock_sendit, (void *)dir, true/*api*/);
+ } else if (strcasecmp(cmd, "running") == 0) {
+ list_running_jobs(bsock_sendit, (void *)dir, true/*api*/);
+ } else if (strcasecmp(cmd, "terminated") == 0) {
+ list_terminated_jobs(bsock_sendit, (void *)dir, true/*api*/);
} else {
pm_strcpy(&jcr->errmsg, dir->msg);
Jmsg1(jcr, M_FATAL, 0, _("Bad .status command: %s\n"), jcr->errmsg);
- bnet_fsend(dir, _("2900 Bad .status command, wrong argument.\n"));
+ dir->fsend(_("2900 Bad .status command, wrong argument.\n"));
bnet_sig(dir, BNET_EOD);
- free_memory(time);
+ free_memory(cmd);
return 0;
}
bnet_sig(dir, BNET_EOD);
- free_memory(time);
+ free_memory(cmd);
return 1;
}