0.0
No commit activity in last 3 years
No release in over 3 years
Read and write Nagios config files from Ruby
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

~> 0.9.2
 Project Readme

NagiosConfig¶ ↑

NagiosConfig provides tools to parse, manipulate, generate and output Nagios configuration files using Ruby.

NagiosConfig::Parser¶ ↑

NagiosConfig::Parser will parse both the object and main style Nagios configuration files, and has both a streaming API and the ability to produce a AST/DOM-like structure.

NagiosConfig::Builder¶ ↑

NagiosConfig::Builder is a simple DSL for generating Nagios config files using Ruby

NagiosConfig::Formater¶ ↑

NagiosConfig::Formater will take the data structures produced by the parser and builder and output them in the format of a Nagios config file.

Making changes to a config file¶ ↑

Say for example you decided you want all your host names uppercase

require 'rubygems'
require 'nagios_config'

host_config = nil
File.open("hosts.cfg") do |f|
  host_config = NagiosConfig::Parser.new.parse(f)
end

host_config.defines do |node|
  if node.type.value == "host"
    variable = node.variables.find {|node| node.name.value == "hostname"}
    variable.val.value.upcase! if variable
  end
end

File.open("hosts.cfg", "w") do |f|
  NagiosConfig::Formatter.new(f).format(host_config)
end