forked from bacula-web/bacula-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjobs.php
337 lines (288 loc) · 11.4 KB
/
jobs.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
<?php
/*
+-------------------------------------------------------------------------+
| Copyright 2010-2016, Davide Franco |
| |
| This program is free software; you can redistribute it and/or |
| modify it under the terms of the GNU General Public License |
| as published by the Free Software Foundation; either version 2 |
| of the License, or (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
+-------------------------------------------------------------------------+
*/
session_start();
require_once('core/global.inc.php');
$view = new CView();
$dbSql = new Bweb($view);
// That's horrible, it must be improved
require_once('core/const.inc.php');
$query = "";
$last_jobs = array();
// Job Status list
define('STATUS_ALL', 0);
define('STATUS_RUNNING', 1);
define('STATUS_WAITING', 2);
define('STATUS_COMPLETED', 3);
define('STATUS_COMPLETED_WITH_ERRORS', 4);
define('STATUS_FAILED', 5);
define('STATUS_CANCELED', 6);
$job_status = array(
STATUS_ALL => 'All',
STATUS_RUNNING => 'Running',
STATUS_WAITING => 'Waiting',
STATUS_COMPLETED => 'Completed',
STATUS_COMPLETED_WITH_ERRORS => 'Completed with errors',
STATUS_FAILED => 'Failed',
STATUS_CANCELED => 'Canceled'
);
$view->assign('job_status', $job_status);
// Global variables
$job_levels = array(
'D' => 'Diff',
'I' => 'Incr',
'F' => 'Full'
);
// Levels list filter
$levels_list = Jobs_Model::getLevels($dbSql->db_link, $job_levels);
$levels_list[''] = 'Any';
$view->assign('levels_list', $levels_list);
// Clients list filter
$clients_list = Clients_Model::getClients($dbSql->db_link);
$clients_list[0] = 'Any';
$view->assign('clients_list', $clients_list);
$query .= "SELECT Job.JobId, Job.Name AS Job_name, Job.Type, Job.StartTime, Job.EndTime, Job.Level, Job.ReadBytes, Job.JobBytes, Job.JobFiles, Pool.Name, Job.JobStatus, Pool.Name AS Pool_name, Status.JobStatusLong ";
$query .= "FROM Job ";
$query .= "LEFT JOIN Pool ON Job.PoolId=Pool.PoolId ";
$query .= "LEFT JOIN Status ON Job.JobStatus = Status.JobStatus ";
// Check job status filter
if (!is_null(CHttpRequest::get_Value('status'))) {
// Selected job status filter
switch(CHttpRequest::get_Value('status')) {
case STATUS_RUNNING:
$query .= "WHERE Job.JobStatus = 'R' ";
break;
case STATUS_WAITING:
$query .= "WHERE Job.JobStatus IN ('F','S','M','m','s','j','c','d','t','p','C') ";
break;
case STATUS_COMPLETED:
$query .= "WHERE Job.JobStatus = 'T' ";
break;
case STATUS_COMPLETED_WITH_ERRORS:
$query .= "WHERE Job.JobStatus = 'E' ";
break;
case STATUS_FAILED:
$query .= "WHERE Job.JobStatus = 'f' ";
break;
case STATUS_CANCELED:
$query .= "WHERE Job.JobStatus = 'A' ";
break;
case STATUS_ALL:
$query .= "WHERE Job.JobStatus != 'xxxx' "; // This code must be improved
break;
}
$view->assign('job_status_filter', CHttpRequest::get_Value('status'));
}
// Selected level filter
if (!is_null(CHttpRequest::get_Value('level_id'))) {
$level_id = CHttpRequest::get_Value('level_id');
$view->assign('level_filter', $level_id);
if (!is_null(CHttpRequest::get_value('status'))) {
if (!empty($level_id)) {
$query .= "AND Job.Level = '$level_id' ";
}
} else {
if (!empty($level_id)) {
$query .= "WHERE Job.Level = '$level_id' ";
}
}
} else {
$view->assign('level_filter', '');
}
// Selected client filter
if (!is_null(CHttpRequest::get_Value('client_id'))) {
$client_id = CHttpRequest::get_Value('client_id');
$view->assign('client_filter', $client_id);
if (!is_null(CHttpRequest::get_value('status'))) {
if ($client_id != 0) {
$query .= "AND Job.ClientId = '$client_id' ";
}
} else {
if ($client_id != 0) {
$query .= "WHERE Job.ClientId = '$client_id' ";
}
}
} else {
$view->assign('client_filter', 0);
}
// Selected start time filter
if (!is_null(CHttpRequest::get_Value('start_time'))) {
$start_time = CHttpRequest::get_Value('start_time');
$view->assign('start_time_filter', $start_time);
if (!is_null(CHttpRequest::get_value('status'))) {
if (!empty($start_time)) {
$query .= "AND Job.StartTime >= '$start_time' ";
}
} else {
if (!empty($start_time)) {
$query .= "WHERE Job.StartTime >= '$start_time' ";
}
}
} else {
$view->assign('start_time_filter', '');
}
// Selected end time filter
if (!is_null(CHttpRequest::get_Value('end_time'))) {
$end_time = CHttpRequest::get_Value('end_time');
$view->assign('end_time_filter', $end_time);
if (!is_null(CHttpRequest::get_value('status'))) {
if (!empty($end_time)) {
$query .= "AND Job.EndTime <= '$end_time' ";
}
} else {
if (!empty($end_time)) {
$query .= "WHERE Job.EndTime <= '$end_time' ";
}
}
} else {
$view->assign('end_time_filter', '');
}
$order_by = '';
$order_by_asc = 'DESC';
$result_order_asc_checked = '';
// Order result by
$result_order = array(
'starttime' => 'Job Start Date',
'endtime' => 'Job End Date',
'jobid' => 'Job Id',
'Job.Name' => 'Job Name',
'jobbytes' => 'Job Bytes',
'jobfiles' => 'Job Files',
'Pool.Name' => 'Pool Name'
);
$view->assign('result_order', $result_order);
// Order by
if (!is_null(CHttpRequest::get_Value('orderby'))) {
$order_by = CHttpRequest::get_Value('orderby');
} else {
$order_by = 'jobid';
}
// Order by DESC || ASC
if (!is_null(CHttpRequest::get_Value('result_order_asc'))) {
$order_by_asc = CHttpRequest::get_Value('result_order_asc');
$result_order_asc_checked = 'checked';
}
$query .= "ORDER BY $order_by $order_by_asc ";
// Set selected option in template for Job order and Job order asc (ascendant order)
$view->assign('result_order_field', $order_by);
$view->assign('result_order_asc_checked', $result_order_asc_checked);
// Jobs per page options
$jobs_per_page = 25;
$view->assign('jobs_per_page', array( 25 => '25', 50 => '50', 75 => '75', 100 => '100', 150 => '150'));
// Determine how many jobs per page
// From config file
if (FileConfig::get_Value('jobs_per_page') != false) {
$jobs_per_page = FileConfig::get_Value('jobs_per_page');
}
// From $_POST form
if (!is_null(CHttpRequest::get_Value('jobs_per_page'))) {
$jobs_per_page = CHttpRequest::get_Value('jobs_per_page');
}
$query .= "LIMIT $jobs_per_page";
$view->assign('jobs_per_page_selected', $jobs_per_page);
// Parsing jobs result
$jobsresult = CDBUtils::runQuery($query, $dbSql->db_link);
foreach ($jobsresult as $job) {
// Determine icon for job status
switch($job['jobstatus']) {
case J_RUNNING:
$job['Job_icon'] = "play";
break;
case J_COMPLETED:
$job['Job_icon'] = "ok";
break;
case J_CANCELED:
$job['Job_icon'] = "off";
break;
case J_COMPLETED_ERROR:
$job['Job_icon'] = "warning-sign";
break;
case J_FATAL:
$job['Job_icon'] = "remove";
break;
case J_WAITING_CLIENT:
case J_WAITING_SD:
case J_WAITING_MOUNT_MEDIA:
case J_WAITING_NEW_MEDIA:
case J_WAITING_STORAGE_RES:
case J_WAITING_JOB_RES:
case J_WAITING_CLIENT_RES:
case J_WAITING_MAX_JOBS:
case J_WAITING_START_TIME:
case J_NOT_RUNNING:
$job['Job_icon'] = "time";
break;
} // end switch
// Job start time, end time and elapsed time
$start_time = $job['starttime'];
$end_time = $job['endtime'];
if ($start_time == '0000-00-00 00:00:00' or is_null($start_time) or $start_time == 0) {
$job['starttime'] = 'n/a';
}
if ($end_time == '0000-00-00 00:00:00' or is_null($end_time) or $end_time == 0) {
$job['endtime'] = 'n/a';
}
// Get the job elapsed time completion
$job['elapsed_time'] = DateTimeUtil::Get_Elapsed_Time($start_time, $end_time);
// Job Level
$job['level'] = $job_levels[$job['level']];
// Job files
$job['jobfiles'] = CUtils::format_Number($job['jobfiles']);
// Set default Job speed and compression rate
$job['speed'] = '0 Mb/s';
$job['compression'] = 'n/a';
switch($job['jobstatus']) {
case J_COMPLETED:
case J_COMPLETED_ERROR:
case J_NO_FATAL_ERROR:
case J_CANCELED:
// Job speed
$seconds = DateTimeUtil::get_ElaspedSeconds($end_time, $start_time);
if ($seconds !== false && $seconds > 0) {
$speed = $job['jobbytes'] / $seconds;
$speed = CUtils::Get_Human_Size($speed, 2) . '/s';
$job['speed'] = $speed;
} else {
$job['speed'] = 'n/a';
}
// Job compression
if ($job['jobbytes'] > 0 && $job['type'] == 'B') {
$compression = (1-($job['jobbytes'] / $job['readbytes']));
$job['compression'] = number_format($compression, 2);
} else {
$job['compression'] = 'n/a';
}
break;
} // end switch
// Job size
$job['jobbytes'] = CUtils::Get_Human_Size($job['jobbytes']);
// Job Pool
if (is_null($job['pool_name'])) {
$job['pool_name'] = 'n/a';
}
$last_jobs[] = $job;
} // end foreach
$view->assign('last_jobs', $last_jobs);
// Count jobs
$view->assign('jobs_found', count($last_jobs));
$view->assign('total_jobs', Jobs_Model::count($dbSql->db_link));
// Set page name
$current_page = 'Jobs report';
$view->assign('page_name', $current_page);
// Language
$view->assign('config_language', FileConfig::get_Value('language'));
// Process and display the template
$view->render('jobs.tpl');