jesse.gonzalez

Distributing preprocessing rules across

Discussion created by jesse.gonzalez on Mar 20, 2010
I wanted a way to sync my preprocessing rules from the master nas to the subordinate pool of hubs running the nas server, so I came up with this.

Use with caution!

-- Distrubute preprocessing rules from the master_nas
-- to the nas_slaves
--
-- @author Jesse Gonzalez
master_nas = "/Your/Master/Hub/nas"

nas_slaves = {
  "/Your/Slave/Hub1/nas",
  "Your/Slave/Hub2/nas"
}

master_getpds = pds.create()
pds.putString(master_getpds, "name", "nas")
ret, rc = nimbus.request( master_nas .. "/controller", "probe_config_get", master_getpds)
pds.delete (master_getpds)

cfg = pds.create()
for index,value in pairs(ret) do
  if (string.match(index, "^/filters")) then
    if (type(value) == "table") then
      for key,value in pairs (value) do
        print (index .. "/" .. key, " = ", value)
        pds.putString(cfg, index .. "/" .. key, value)
      end
    end
  end
end

-- clearcfg pds to clear the existing /filters section
clearcfg = pds.create()
pds.putString(clearcfg, "name", "nas")
pds.putString(clearcfg, "section", "/filters")

-- populatecfg pds to populate a new /filters section
populatecfg = pds.create()
pds.putString (populatecfg, "name", "nas")
pds.putPDS (populatecfg, "as_pds", cfg)

-- restart pds to restart the nas probe after applying changes
restart = pds.create()

for index, nas_slave in pairs (nas_slaves) do
  print( "** " .. nas_slave .. " **" )
 
  ret2, rc2 = nimbus.request (nas_slave .. "/controller", "probe_config_set", clearcfg)
  if (rc2 ~= 0) then
    print ("There was an error clearing the /filter section for the nas on " .. nas_slave)
  end

  ret2, rc2 = nimbus.request (nas_slave .. "/controller", "probe_config_set", populatecfg)
  if (rc2 ~= 0) then
    print ("There was an error populating the /filter section for the nas on  " .. nas_slave)
  end

  ret2, rc2 = nimbus.request (nas_slave .. "/nas", "_restart", restart)
  if (rc2 ~= 0) then
    print ("There was an error restarting the nas on  " .. nas_slave)
  end
end

pds.delete (restart)
pds.delete (populatecfg)
pds.delete (clearcfg)
pds.delete (cfg)

Outcomes