View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0000821 | bareos-core | General | public | 2017-05-13 08:00 | 2018-06-08 14:10 |
Reporter | loli10K | Assigned To | |||
Priority | low | Severity | feature | Reproducibility | N/A |
Status | closed | Resolution | no change required | ||
Product Version | 16.2.4 | ||||
Summary | 0000821: [PATCH] Add "%S" (Elapsed time) to expanded character list in RunScript Command | ||||
Description | I've been working to integrate bareos with my monitoring system and i needed an easy way to access information about the job elapsed time in the context of a RunScript Command. I'm running the attached patch on my setup, i hope you find it useful too. | ||||
Additional Information | The docs should be updated too, probably. I don't know how. Also we can change the character "S" with any other, i'm not married to that. | ||||
Tags | No tags attached. | ||||
0002-Add-S-Elapsed-time-to-expanded-character-list-in-Run.patch (1,247 bytes)
From 9d6fda366993022e4734e6e03f01157c7b819617 Mon Sep 17 00:00:00 2001 From: loli10K <ezomori.nozomu@gmail.com> Date: Sat, 13 May 2017 07:45:52 +0200 Subject: [PATCH 2/2] Add "%S" (Elapsed time) to expanded character list in RunScript Command --- src/lib/util.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/lib/util.c b/src/lib/util.c index 71bb498..24c8f39 100644 --- a/src/lib/util.c +++ b/src/lib/util.c @@ -781,6 +781,7 @@ void decode_session_key(char *decode, char *session, char *key, int maxlen) * %n = Unadorned Job name * %r = Recipients * %s = Since time + * %S = Elapsed time * %t = Job type (Backup, ...) * %v = Volume name(s) * @@ -884,6 +885,13 @@ POOLMEM *edit_job_codes(JCR *jcr, char *omsg, char *imsg, const char *to, job_co str = _("*None*"); } break; + case 'S': /* Elapsed time */ + if (jcr) { + str = edit_uint64(jcr->end_time - jcr->start_time, add); + } else { + str = _("*None*"); + } + break; case 't': /* Job type */ if (jcr) { str = job_type_to_str(jcr->getJobType()); -- 2.7.4 |
|
Thank you for providing this patch. Lets see, if I understood it correctly: %S would only make sense, when the RunScript did run after the Backup Job. Have you checked, what happens when it is called "Before" or "AfterVSS". If it returns 0, this would be okay. But if the negative result is cast to an unsigned int, it would be messy. If this is intended for monitoring, consider writing a simple Bareos Director Python Plugin instead, like: import bareosdir def __init__(self, context, plugindef): events = [ bDirEventType['bDirEventJobEnd'] ] bareosdir.RegisterEvents(context, events) def handle_plugin_event(self, context, event): if event == bDirEventType['bDirEventJobEnd']: self.send_to_monitoring(self.jobRunningTime) A more complex example can be found at See https://github.com/bareos/bareos-contrib/tree/master/dir-plugins/nagios_icinga |
|
You're right, unfortunately this won't work correctly when called "Before" or "AfterVSS": --- being paste --- (gdb) bt #0 edit_job_codes (jcr=0xb5f01ef0, omsg=0xb49035b0 "sh -c 'echo ", imsg=0xdd668 "sh -c 'echo %S %c %i %e %l > /tmp/test'", to=0xb6ed2e50 "", callback=0x2e4cd <job_code_callback_director(JCR*, char const*)>) at util.c:889 0000001 0xb6ebf35c in RUNSCRIPT::run (this=0xdd618, jcr=0xb5f01ef0, name=0x8cae8 "BeforeJob") at runscript.c:270 0000002 0xb6ebf10c in run_scripts (jcr=0xb5f01ef0, runscripts=0xdc468, label=0x8cae8 "BeforeJob", allowed_script_dirs=0x0) at runscript.c:212 0000003 0x000391a4 in job_thread (arg=0xb5f01ef0) at job.c:453 0000004 0x0003dcf4 in jobq_server (arg=0xb9af8 <job_queue>) at jobq.c:484 0000005 0xb6eb4672 in lmgr_thread_launcher (x=0xb5f00e18) at lockmgr.c:926 0000006 0xb6c91f88 in start_thread (arg=0xb30ff450) at pthread_create.c:311 0000007 0xb6aca0fc in ?? () at ../ports/sysdeps/unix/sysv/linux/arm/nptl/../clone.S:92 from /lib/arm-linux-gnueabihf/libc.so.6 Backtrace stopped: previous frame identical to this frame (corrupt stack?) (gdb) p jcr->end_time $7 = 0 (gdb) p jcr->start_time $8 = 1498152096 (gdb) p (uint64_t)(jcr->end_time - jcr->start_time) $9 = 18446744072211399520 (gdb) detach Detaching from program: /usr/sbin/bareos-dir, process 363 (gdb) quit root@bareos:/tmp# cat /tmp/test 18446744072211399520 windows7-fd 327 Error Full --- end paste --- Python plugins could be a viable option, thanks for mentioning those, but i don't know if i can get those to run, my bareos server is hosted on a raspberry, so keeping my system lightweight is very important. I will try to get python plugins to run when i have more time, in then meantime we could fix my original patch with something like: -- being pseudocode --- if (jcr->end_time < jcr->start_time) { return 0 } else { return jcr->end_time - jcr->start_time } --- end pseudocode --- |
|
Sorry for taking so long: i have replaced my "RunScript Command"-based monitoring with a custom python plugin as suggested, i think we can close this. | |
Excellent. Thank you for coming back on this. You might want to publish your plugin. https://github.com/bareos/bareos-contrib might be a good place for it. | |
Date Modified | Username | Field | Change |
---|---|---|---|
2017-05-13 08:00 | loli10K | New Issue | |
2017-05-13 08:00 | loli10K | File Added: 0002-Add-S-Elapsed-time-to-expanded-character-list-in-Run.patch | |
2017-06-22 14:22 | joergs | Note Added: 0002675 | |
2017-06-22 14:22 | joergs | Status | new => feedback |
2017-06-22 19:40 | loli10K | Note Added: 0002676 | |
2017-06-22 19:40 | loli10K | Status | feedback => new |
2018-01-24 23:08 | loli10K | Note Added: 0002882 | |
2018-01-25 10:49 | joergs | Note Added: 0002883 | |
2018-01-25 10:50 | joergs | Status | new => resolved |
2018-01-25 10:50 | joergs | Resolution | open => no change required |
2018-06-08 14:10 | joergs | Status | resolved => closed |