Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Array data use within a template

I have taken the NRPE plugin (for Nagios) from the puppet forge and tweaked it in order to get it to work for NCPA as well as NRPE. Without getting too much into it, they went from an include directory in NRPE, to defining the checks in a single config file with NCPA, so in order to modify the passive checks, they need to be looped through from the array..

While I have it working functionally, I am running into issues where the manifest runs almost every check-in, as the array is not necessarily parsed in the same order as the last time it ran, so the template always reorders the commands..

What I have is :

Defined the variables in the manifest :

$ncpa_passive_checks = {  
 "check root partition" => {
     "test_name" => "disk usage",
     "args"      => "--warning 20% --critical 10% -p /",
     "ncpa_branch" => "/disk/logical/|boot/used_percent",
 "swap usage" => {
      "test_name" => "swap usage",
      "args"      => "--warning 40 --critical 80",
      "ncpa_branch" => "/memory/swap/percent", 
   "cpu util" => {
      "test_name" => "cpu usage",
      "args"      => "--warning 85 --critical 90",
      "ncpa_branch" => "/cpu/percent",
   "memory usage" => {
      "test_name" => "memory usage",
       "args"     => "--warning 80 --critical 90",
       "ncpa_branch" => "/memory/virtual/percent",

Elsewhere in the manifest i am performing the following:

if $ncpa_passive_checks != undef {
  $passive_checks = hiera('nagios::ncpa_passive_checks', {} )
  create_resources('nagios::ncpa_passive_checks', $passive_checks)

and the template is doing the following in order to place the passive commands into the config file:

<% @ncpa_passive_checks.each do | key,hash | %>%HOSTNAME%|<%= hash['test_name'] %> = <%= hash['ncpa_branch']%> <%= hash['args'] %>

I do get the output that I expect to get, but the order changes each run..

I KNOW there is going to be a better way to do this, but this is really my first experience with using arrays in this manner within puppet.. Does anyone know how I should be doing this instead, so that it is going to only run when something truly has changed?

Thx for any help!