So, I use munin to monitor a couple hundred servers and I love it. I am trying to tweak the alert text to look a little different however, and I'm not understanding how to get it to do what I want.

I have read http://guide.munin-monitoring.org/en/latest/tutorial/alert.html and http://munin-monitoring.org/wiki/MuninAlertVariables and have no problems with the variables etc. I want to change the syntax. More specifically, here is the default text formatting out of the perl module:

'${var:group} :: ${var:host} :: ${var:graph_title}${if:cfields \n\tCRITICALs:${loop<,>:cfields  ${var:label} is ${var:value} (outside range [${var:crange}])${if:extinfo : ${var:extinfo}}}.}${if:wfields \n\tWARNINGs:${loop<,>:wfields  ${var:label} is ${var:value} (outside range [${var:wrange}])${if:extinfo : ${var:extinfo}}}.}${if:ufields \n\tUNKNOWNs:${loop<,>:ufields  ${var:label} is ${var:value}${if:extinfo : ${var:extinfo}}}.}${if:fofields \n\tOKs:${loop<,>:fofields  ${var:label} is ${var:value}${if:extinfo : ${var:extinfo}}}.}\n',

as the above document states, this will output something like this:

dev :: hostname.dev :: Memory usage OKs: swap is 779112448.00.

I currently have rewritten the formatting as:

${if:cfields CRITICAL} ${if:wfields WARNING} ${if:fofields OK} '${var:group} :: ${var:host} :: ${var:graph_title}\n${if:cfields CRITICAL :${loop<,>:cfields  ${var:label} is ${var:value} (outside range [${var:crange}])${if:extinfo : ${var:extinfo}}}.\n\t}${if:wfields WARNING :${loop<,>:wfields  ${var:label} is ${var:value} (outside range [${var:wrange}])${if:extinfo : ${var:extinfo}}}.\n\t}${if:ufields UNKNOWN :${loop<,>:ufields  ${var:label} is ${var:value}${if:extinfo : ${var:extinfo}}}.\n\t}${if:fofields OK :${loop<,>:fofields  ${var:label} is ${var:value}${if:extinfo : ${var:extinfo}}}.}'

The reason behind this is that I want the Severity to show up first in order of most severe to least severe.

Output ends up looking like this, and then I can filter messages by their severity pretty nicely.:

'CRITICAL':'dev :: hostname.dev :: Memory usage CRITICAL : swap is 1706340352.00 (outside range [:1000000000]).'

This is "functioning" for what I want in terms of the severity, but I would like to make it prettier because some messages come through with both CRITICAL and WARNING and OK all at the same time and end up looking like this:

'WARNING':'OK dev :: hostname.dev .....

I know why this is, the logic in my format says "If there are cfield, output CRITICAL. Then if there are wfield, output WARNING..." etc. I would like it to only output the most severe of the three and not 2 or all three if they all exist.

In my brain I can come up with the logic for it (If there are cfields, output CRITICAL, if there aren't cfields, and there are wfields, output WARNING, if there aren't cfields or wfields, but there are fofields, then output OK.) However, I have no idea what format method or language this is written in. Munin the program is all written in Perl, but I can't find anything online referencing this syntax in Perl or any other language for that matter (my google fu must not be strong today).

So, does anyone know how to help me here? TLDR, in this syntax (where ${if:cfields CRITICAL} means IF cfields exist, then print CRITICAL) what is the correct way to write: IF cfields don't exist AND wfields exist THEN print WARNING.



The allowable syntax for the expansion can be seen in the message_expand function in LimitsOld.pm. As far as I can tell it doesn't implement enough control structures to do what you want.

Alternative approach would be to pass the notifications through an intermediary (Nagios for example or a script of your own devising) and apply logic/reformatting there.

  • Thanks for pointing out the source. That was very helpful. I'm moving on to reformatting by script afterwards. – Joe Apr 22 '15 at 20:09

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.