« The risk of high uptimes....Moving irssi »

Last two weekends - nagios and more cfengine 2 & 3


  01:14:00 pm, by The Dreamer   , 3144 words  
Categories: Software, Operating Systems, Ubuntu, FreeBSD, CFEngine

Last two weekends - nagios and more cfengine 2 & 3

I then realize that the graph template seems to be missing stuff...stuff of interest that were present when it was just using the default template. Probably silly things to normal people I suppose...but I wanted graphs for external command buffer usage, run time, status file age and pid !

So, I decide instead of creating a symlink of 'check_nagiostats.php -> nagiostats.php' in /usr/local/www/pnp/templates.dist, that I would use edit_file to create a /usr/local/www/pnp/templates/check_nagiostats.php file based on /usr/local/www/pnp/templates.dist/nagiostats.php.

So, I use a similar edit_line process that I used to create second instance rc files.


                comment         => "Create check_nagiostats template",
                create          => "true",
                edit_line       => create_check_nagiostats("$(pnp_nagiostats)"),
                edit_defaults   => empty,
                perms           => mog("0644","root","$(g.group)"),
                action          => if_elapsed("60");


bundle edit_line create_check_nagiostats(f)

                insert_type => "file";

And, then I foolish try to type what I want inserted as a great big line after this, typing out $(const.dollar) everywhere I need a dollar-sign and \" where needed. This doesn't work. Even after cleaning up all the typos I had had along the way.

There are lines missing.

all the lines of:

foreach ($(const.dollar)this->DS as $(const.dollar)KEY=>$(const.dollar)VAL){

are missing. Alone with all the lines that are just close parens.

After some fiddling with like adding backslashes or altering the line and then using a later replace_patterns: to make it right. I decide that what I should do is put what I want into a file and insert that as well.

So, here's what I added to my check_nagiostats.php file:


$opt[4] = '--title "External Command Buffers"';
$ds_name[4] = "Command Buffers";
$def[4] = "";
$i 1;
foreach ($this->DS as $KEY=>$VAL){
    if(preg_match('/(.*)BUF$/'$VAL['NAME'], $matches)){
    $label ucfirst(strtolower($matches[1]));
    $def[4] .= rrd::def    ("var$KEY"$VAL['RRDFILE'], $VAL['DS'], "AVERAGE");
    $def[4]    .= rrd::line1    ("var$KEY"rrd::color($i), rrd::cut($label,10) );
    $def[4] .= rrd::gprint    ("var$KEY"array("LAST"), "%8.2lf");
$opt[5] = '--title "Nagios Run Time"';
$ds_name[5] = "Run Time";
$def[5] = "";
$i 1;
foreach ($this->DS as $KEY=>$VAL){
    if(preg_match('/PROGRUNTIMETT/'$VAL['NAME'], $matches)){
    $label "Run Time";
    $def[5] .= rrd::def    ("var$KEY"$VAL['RRDFILE'], $VAL['DS'], "AVERAGE");
    $def[5] .= rrd::cdef    ("var_days$KEY""var$KEY,86400,/");
    $def[5] .= rrd::area    ("var_days$KEY"rrd::color($i), rrd::cut($label,10) );
    $def[5]    .= rrd::gprint    ("var_days$KEY"array("LAST","MAX"), "%8.2lf");
$opt[6] = '--title "Status File Age"';
$ds_name[6] = "Status File Age";
$def[6] = "";
$i 1;
foreach ($this->DS as $KEY=>$VAL){
    if(preg_match('/STATUSFILEAGETT/'$VAL['NAME'], $matches)){
    $label "File Age";
    $def[6] .= rrd::def    ("var$KEY"$VAL['RRDFILE'], $VAL['DS'], "AVERAGE");
    $def[6]    .= rrd::area    ("var$KEY"rrd::color($i), rrd::cut($label,10) );
    $def[6] .= rrd::gprint    ("var$KEY"array("LAST","MAX","AVERAGE"), "%8.2lf");
$opt[7] = '--title "Nagios Process ID"';
$ds_name[7] = "Nagios Process ID";
$def[7] = "";
$i 1;
foreach ($this->DS as $KEY=>$VAL){
    if(preg_match('/NAGIOSPID/'$VAL['NAME'], $matches)){
    $label "Nagios PID";
    $def[7] .= rrd::def    ("var$KEY"$VAL['RRDFILE'], $VAL['DS'], "AVERAGE");
    $def[7]    .= rrd::area    ("var$KEY"rrd::color($i), rrd::cut($label,10) );
    $def[7] .= rrd::gprint    ("var$KEY"array("LAST"), "%8.2lf");

And add this to my edit_line bundle

                insert_type => "file",
                location => before("\?>");

This still doesn't work...same problem of missing lines as before.

So, I'm hunting around online as to why this is happening, find some bug reports here and there (one that sounds like my issue, with Nick Anderson in the discussion again... #2315 saying he's run into in 3.5.0). Though I'm not familiar with preserve_block, so I check the reference manual.... and find this note:


The default is to treat the promiser as a literal string of convergent lines (the values literal and string are synonymonous).

The default behaviour assumes that multi-line entries are not ordered specifically, and should be treated as a collection of lines of text and not as a single unbroken object.

If the option ‘preserve_block’ is used, then CFEngine will not break up multiple lines into individual, non-ordered objects, so that the block of text will be preserved. Even if some of the lines in the block already exist, they will be added again as a coherent block. Thus if you suspect that some stray / conflicting lines might be present they should be cleaned up with delete_lines first.

The value file is used to tell CFEngine that the string is non-literal and should be interpreted as a filename from which to import lines, see insert_select. Inserted files assume non-‘preserve_block’ semantics. An equivalent files setting that does preserve the ordering of lines in the file is called file_preserve_block. This was added in CFEngine Core 3.5.x.

Wow, the default is kind of annoying, but explains why lines are missing...though I suppose it makes some sense now that I know about it.

So, since I'm running CFEngine 3.5.1, I can try

                insert_type => "file_preserve_block",
                location => before("\?>");

instead. This works.

I then think about writing something up, but I run into the end of the weekend and I don't find the time during the week to write anything...so it might not happen. Yesterday I purged a bunch of drafts from my blog, some over a year old.... But, then I run into the cfengine work that I want to write a bit about now....

Pages: · 2·

No feedback yet

Now instead of subjecting some poor random forum to a long rambling thought, I will try to consolidate those things into this blog where they can be more easily ignored profess to be collected thoughts from my mind.

Latest Poopli Updaters -- http://lkc.me/poop


There are 17 years 3 months 22 days 23 hours 13 minutes and 45 seconds until the end of time.
And, it has been 7 years 9 months 4 days 14 hours 49 minutes and 11 seconds since The Doctor saved us all from the end of the World!


September 2020
Mon Tue Wed Thu Fri Sat Sun
 << <   > >>
  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        


  XML Feeds

Who's Online?

  • Guest Users: 2
This seal is issued to lawrencechen.net by StopTheHacker Inc.
Photo gallery software

hosted by
Green Web Hosting! This site hosted by DreamHost.

monitored by
Monitored by eXternalTest
SiteUptime Web Site Monitoring Service
website uptime