Bareos Bug Tracker
Bareos Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0000821bareos-core[All Projects] Generalpublic2017-05-13 08:002018-06-08 14:10
Reporterloli10K 
Assigned To 
PrioritylowSeverityfeatureReproducibilityN/A
StatusclosedResolutionno change required 
PlatformOSOS Version
Product Version16.2.4 
Target VersionFixed in Version 
Summary0000821: [PATCH] Add "%S" (Elapsed time) to expanded character list in RunScript Command
DescriptionI'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 InformationThe 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.
TagsNo tags attached.
bareos-master: impact
bareos-master: action
bareos-17.2: impact
bareos-17.2: action
bareos-16.2: impact
bareos-16.2: action
bareos-15.2: impact
bareos-15.2: action
bareos-14.2: impact
bareos-14.2: action
bareos-13.2: impact
bareos-13.2: action
bareos-12.4: impact
bareos-12.4: action
Attached Filespatch file icon 0002-Add-S-Elapsed-time-to-expanded-character-list-in-Run.patch [^] (1,247 bytes) 2017-05-13 08:00 [Show Content]

- Relationships

-  Notes
(0002675)
joergs (administrator)
2017-06-22 14:22

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 [^]
(0002676)
loli10K (reporter)
2017-06-22 19:40

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 ---
(0002882)
loli10K (reporter)
2018-01-24 23:08

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.
(0002883)
joergs (administrator)
2018-01-25 10:49

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.

- Issue History
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


Copyright © 2000 - 2018 MantisBT Team
Powered by Mantis Bugtracker