2 Bacula® - The Network Backup Solution
4 Copyright (C) 2008-2014 Free Software Foundation Europe e.V.
6 The main author of Bacula is Kern Sibbald, with contributions from many
7 others, a complete list can be found in the file AUTHORS.
9 You may use this file and others of this release according to the
10 license defined in the LICENSE file, which includes the Affero General
11 Public License, v3.0 ("AGPLv3") and some additional permissions and
12 terms pursuant to its AGPLv3 Section 7.
14 Bacula® is a registered trademark of Kern Sibbald.
17 * Status packet definition that is used in both the SD and FD. It
18 * permits Win32 to call output_status() and get the output back
19 * at the callback address line by line, and for Linux code,
20 * the output can be sent directly to a BSOCK.
22 * Kern Sibbald, March MMVII
32 * Packet to send to output_status()
36 BSOCK *bs; /* used on Unix machines */
37 void *context; /* Win32 */
38 void (*callback)(const char *msg, int len, void *context); /* Win32 */
39 char api_opts[MAX_NAME_LENGTH];
40 int api; /* set if we want API output, with api level */
43 STATUS_PKT() { memset(this, 0, sizeof(STATUS_PKT)); };
47 extern void output_status(STATUS_PKT *sp);
50 * Send to bsock (Director or Console)
52 static void sendit(const char *msg, int len, STATUS_PKT *sp)
56 user->msg = check_pool_memory_size(user->msg, len+1);
57 memcpy(user->msg, msg, len+1);
61 sp->callback(msg, len, sp->context);
66 static void list_terminated_jobs(STATUS_PKT *sp)
68 char dt[MAX_TIME_LENGTH], b1[30], b2[30];
70 struct s_last_job *je;
73 msg = _("\nTerminated Jobs:\n");
74 if (!sp->api) sendit(msg, strlen(msg), sp);
75 if (last_jobs->size() == 0) {
76 if (!sp->api) sendit("====\n", 5, sp);
79 lock_last_jobs_list();
80 msg = _(" JobId Level Files Bytes Status Finished Name \n");
81 if (!sp->api) sendit(msg, strlen(msg), sp);
82 msg = _("===================================================================\n");
83 if (!sp->api) sendit(msg, strlen(msg), sp);
84 foreach_dlist(je, last_jobs) {
85 char JobName[MAX_NAME_LENGTH];
89 bstrftime_nc(dt, sizeof(dt), je->end_time);
90 switch (je->JobType) {
93 bstrncpy(level, " ", sizeof(level));
96 bstrncpy(level, job_level_to_str(je->JobLevel), sizeof(level));
100 switch (je->JobStatus) {
102 termstat = _("Created");
105 case JS_ErrorTerminated:
106 termstat = _("Error");
109 termstat = _("Diffs");
112 termstat = _("Cancel");
118 termstat = _("OK -- with warnings");
122 termstat = _("Other");
125 bstrncpy(JobName, je->Job, sizeof(JobName));
126 /* There are three periods after the Job name */
128 for (int i=0; i<3; i++) {
129 if ((p=strrchr(JobName, '.')) != NULL) {
134 bsnprintf(buf, sizeof(buf), _("%6d\t%-6s\t%8s\t%10s\t%-7s\t%-8s\t%s\n"),
137 edit_uint64_with_commas(je->JobFiles, b1),
138 edit_uint64_with_suffix(je->JobBytes, b2),
142 bsnprintf(buf, sizeof(buf), _("%6d %-6s %8s %10s %-7s %-8s %s\n"),
145 edit_uint64_with_commas(je->JobFiles, b1),
146 edit_uint64_with_suffix(je->JobBytes, b2),
150 sendit(buf, strlen(buf), sp);
152 unlock_last_jobs_list();
154 sendit("====\n", 5, sp);
158 #if defined(HAVE_WIN32)
162 # define BAC_COMPONENT "Client"
164 # define BAC_COMPONENT "Storage"
167 /* Return a one line status for the tray monitor */
168 char *bac_status(char *buf, int buf_len)
171 const char *termstat = _("Bacula " BAC_COMPONENT ": Idle");
172 struct s_last_job *job;
173 int stat = 0; /* Idle */
178 Dmsg0(1000, "Begin bac_status jcr loop.\n");
180 if (njcr->JobId != 0) {
182 termstat = _("Bacula " BAC_COMPONENT ": Running");
191 if (last_jobs->size() > 0) {
192 job = (struct s_last_job *)last_jobs->last();
193 stat = job->JobStatus;
194 switch (job->JobStatus) {
196 termstat = _("Bacula " BAC_COMPONENT ": Last Job Canceled");
198 case JS_ErrorTerminated:
200 termstat = _("Bacula " BAC_COMPONENT ": Last Job Failed");
204 termstat = _("Bacula " BAC_COMPONENT ": Last Job had Warnings");
209 Dmsg0(1000, "End bac_status jcr loop.\n");
213 bstrncpy(buf, termstat, buf_len);
218 #endif /* HAVE_WIN32 */