Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust Nagios lens to handle resources.cfg #13

Merged
merged 2 commits into from
Jan 8, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 56 additions & 29 deletions lenses/nagioscfg.aug
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(*
Module: NagiosConfig
Parses /etc/nagios3/*.cfg
Parses /etc/{nagios{3,},icinga/*.cfg

Authors: Sebastien Aperghis-Tramoni <[email protected]>
Raphaël Pinson <[email protected]>
Expand All @@ -12,35 +12,62 @@ About: Lens Usage
To be documented

About: Configuration files
This lens applies to /etc/nagios3/*.cfg. See <filter>.
This lens applies to /etc/{nagios{3,},icinga/*.cfg. See <filter>.
*)

module NagiosCfg =
autoload xfm

(* View: param_def
define a field *)
let param_def =
let space_in = /[^ \t\n][^\n=]*[^ \t\n]|[^ \t\n]/
in key /[A-Za-z0-9_]+/
. Sep.space_equal
. store space_in

(* View: param
Params can have sub params *)
let param =
[ Util.indent . param_def
. [ Sep.space . param_def ]*
. Util.eol ]

(* View: lns
main structure *)
let lns = ( Util.empty | Util.comment | param )*

(* View: filter *)
let filter = incl "/etc/nagios3/*.cfg"
. excl "/etc/nagios3/commands.cfg"
. excl "/etc/nagios3/resource.cfg"

let xfm = transform lns filter
autoload xfm

(************************************************************************
* Group: Utility variables/functions
************************************************************************)
(* View: param_def
define a field *)
let param_def =
let space_in = /[^ \t\n][^\n=]*[^ \t\n]|[^ \t\n]/
in key /[A-Za-z0-9_]+/
. Sep.space_equal
. store space_in

(* View: macro_def
Macro line, as used in resource.cfg *)
let macro_def =
let macro = /\$[A-Za-z0-9]+\$/
in let macro_decl = Rx.word | Rx.fspath
in key macro . Sep.space_equal . store macro_decl

(************************************************************************
* Group: Entries
************************************************************************)
(* View: param
Params can have sub params *)
let param =
[ Util.indent . param_def
. [ Sep.space . param_def ]*
. Util.eol ]

(* View: macro *)
let macro = [ Util.indent . macro_def . Util.eol ]

(************************************************************************
* Group: Lens
************************************************************************)
(* View: entry
Define the accepted entries, such as param for regular configuration
files, and macro for resources.cfg .*)
let entry = param
| macro

(* View: lns
main structure *)
let lns = ( Util.empty | Util.comment | entry )*

(* View: filter *)
let filter = incl "/etc/nagios3/*.cfg"
. incl "/etc/nagios/*.cfg"
. incl "/etc/icinga/*.cfg"
. excl "/etc/nagios3/commands.cfg"
. excl "/etc/nagios/commands.cfg"
. incl "/etc/icinga/commands.cfg"

let xfm = transform lns filter
6 changes: 4 additions & 2 deletions lenses/nagiosobjects.aug
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(*
Module: NagiosObjects
Parses /etc/nagios3/objects/*.cfg
Parses /etc/{nagios{3,},icinga/objects/*.cfg

Authors: Sebastien Aperghis-Tramoni <[email protected]>
Raphaël Pinson <[email protected]>
Expand All @@ -13,7 +13,7 @@ About: Lens Usage

About: Configuration files

This lens applies to /etc/nagios3/objects/*.cfg. See <filter>.
This lens applies to /etc/{nagios{3,},icinga/objects/*.cfg. See <filter>.
*)

module NagiosObjects =
Expand Down Expand Up @@ -52,6 +52,8 @@ module NagiosObjects =
let lns = ( empty | comment | object_def )*

let filter = incl "/etc/nagios3/objects/*.cfg"
. incl "/etc/nagios/objects/*.cfg"
. incl "/etc/icinga/objects/*.cfg"

let xfm = transform lns filter

11 changes: 11 additions & 0 deletions lenses/tests/test_nagioscfg.aug
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
(*
Module: Test_NagiosCfg
Provides unit tests and examples for the <NagiosCfg> lens.
*)

module Test_NagiosCfg =
let conf="
# LOG FILE
Expand Down Expand Up @@ -76,3 +81,9 @@ let space_in = "nagios_check_command=/usr/lib/nagios/plugins/check_nagios /var/c

test NagiosCfg.lns get space_in =
{ "nagios_check_command" = "/usr/lib/nagios/plugins/check_nagios /var/cache/nagios3/status.dat 5 '/usr/sbin/nagios3'" }

test NagiosCfg.lns get "$USER1$=/usr/local/libexec/nagios\n" =
{ "$USER1$" = "/usr/local/libexec/nagios" }

test NagiosCfg.lns get "$USER3$=somepassword\n" =
{ "$USER3$" = "somepassword" }