2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2016 Kern Sibbald
6 The original author of Bacula is Kern Sibbald, with contributions
7 from many 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 This notice must be preserved when any source code is
15 conveyed and/or propagated.
17 Bacula(R) is a registered trademark of Kern Sibbald.
20 * Status packet definition that is used in both the SD and FD. It
21 * permits Win32 to call output_status() and get the output back
22 * at the callback address line by line, and for Linux code,
23 * the output can be sent directly to a BSOCK.
25 * Kern Sibbald, March MMVII
33 * Packet to send to output_status()
37 BSOCK *bs; /* used on Unix machines */
38 void *context; /* Win32 */
39 void (*callback)(const char *msg, int len, void *context); /* Win32 */
40 char api_opts[MAX_NAME_LENGTH];
41 int api; /* set if we want API output, with api level */
44 STATUS_PKT() { memset(this, 0, sizeof(STATUS_PKT)); };
48 extern void output_status(STATUS_PKT *sp);
51 * Send to bsock (Director or Console)
53 static void sendit(const char *msg, int len, STATUS_PKT *sp)
57 user->msg = check_pool_memory_size(user->msg, len+1);
58 memcpy(user->msg, msg, len+1);
62 sp->callback(msg, len, sp->context);
66 #ifndef STATUS_FUNCTIONS
67 #define STATUS_FUNCTIONS
70 static void list_terminated_jobs(STATUS_PKT *sp)
72 char dt[MAX_TIME_LENGTH], b1[30], b2[30];
74 struct s_last_job *je;
77 msg = _("\nTerminated Jobs:\n");
78 if (!sp->api) sendit(msg, strlen(msg), sp);
79 if (last_jobs->size() == 0) {
80 if (!sp->api) sendit("====\n", 5, sp);
83 lock_last_jobs_list();
84 msg = _(" JobId Level Files Bytes Status Finished Name \n");
85 if (!sp->api) sendit(msg, strlen(msg), sp);
86 msg = _("===================================================================\n");
87 if (!sp->api) sendit(msg, strlen(msg), sp);
88 foreach_dlist(je, last_jobs) {
89 char JobName[MAX_NAME_LENGTH];
93 bstrftime_nc(dt, sizeof(dt), je->end_time);
94 switch (je->JobType) {
97 bstrncpy(level, " ", sizeof(level));
100 bstrncpy(level, job_level_to_str(je->JobLevel), sizeof(level));
104 switch (je->JobStatus) {
106 termstat = _("Created");
109 case JS_ErrorTerminated:
110 termstat = _("Error");
113 termstat = _("Diffs");
116 termstat = _("Cancel");
122 termstat = _("OK -- with warnings");
125 termstat = _("Incomplete");
128 termstat = _("Other");
131 bstrncpy(JobName, je->Job, sizeof(JobName));
132 /* There are three periods after the Job name */
134 for (int i=0; i<3; i++) {
135 if ((p=strrchr(JobName, '.')) != NULL) {
140 bsnprintf(buf, sizeof(buf), _("%6d\t%-6s\t%8s\t%10s\t%-7s\t%-8s\t%s\n"),
143 edit_uint64_with_commas(je->JobFiles, b1),
144 edit_uint64_with_suffix(je->JobBytes, b2),
148 bsnprintf(buf, sizeof(buf), _("%6d %-6s %8s %10s %-7s %-8s %s\n"),
151 edit_uint64_with_commas(je->JobFiles, b1),
152 edit_uint64_with_suffix(je->JobBytes, b2),
156 sendit(buf, strlen(buf), sp);
158 unlock_last_jobs_list();
160 sendit("====\n", 5, sp);
164 #if defined(HAVE_WIN32)
168 # define BAC_COMPONENT "Client"
170 # define BAC_COMPONENT "Storage"
173 /* Return a one line status for the tray monitor */
174 char *bac_status(char *buf, int buf_len)
177 const char *termstat = _("Bacula " BAC_COMPONENT ": Idle");
178 struct s_last_job *job;
179 int stat = 0; /* Idle */
184 Dmsg0(1000, "Begin bac_status jcr loop.\n");
186 if (njcr->JobId != 0) {
188 termstat = _("Bacula " BAC_COMPONENT ": Running");
197 if (last_jobs->size() > 0) {
198 job = (struct s_last_job *)last_jobs->last();
199 stat = job->JobStatus;
200 switch (job->JobStatus) {
202 termstat = _("Bacula " BAC_COMPONENT ": Last Job Canceled");
204 case JS_ErrorTerminated:
206 termstat = _("Bacula " BAC_COMPONENT ": Last Job Failed");
210 termstat = _("Bacula " BAC_COMPONENT ": Last Job had Warnings");
215 Dmsg0(1000, "End bac_status jcr loop.\n");
219 bstrncpy(buf, termstat, buf_len);
224 #endif /* HAVE_WIN32 */
226 #endif /* ! STATUS_FUNCTIONS */