Signed-off-by: Marc Fournier <[email protected]> --- lenses/nrpe.aug | 89 ++++++++++++++++++++++++++++++++++++++++++++ lenses/tests/test_nrpe.aug | 88 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 177 insertions(+), 0 deletions(-) create mode 100644 lenses/nrpe.aug create mode 100644 lenses/tests/test_nrpe.aug
diff --git a/lenses/nrpe.aug b/lenses/nrpe.aug new file mode 100644 index 0000000..5241fe9 --- /dev/null +++ b/lenses/nrpe.aug @@ -0,0 +1,89 @@ +(* +Module: Nrpe + Parses nagios-nrpe configuration files. + +Author: Marc Fournier <[email protected]> + +About: License + This file is licensed under the LGPLv2+, like the rest of Augeas. +*) + +module Nrpe = + autoload xfm + +let nl = del /[ \t]*\n/ "\n" +let eq = del /=/ "=" + + +(* command entries + +nrpe.cfg usually has many entries defining commands to run + +command[check_foo]=/path/to/nagios/plugin -w 123 -c 456 +command[check_bar]=/path/to/another/nagios/plugin --option + +*) +let obrkt = del /\[/ "[" +let cbrkt = del /\]/ "]" + +let command = [ key "command" . + [ obrkt . key /[^]\/\n]+/ . cbrkt . eq . store /[^=\n]+/ . del /\n/ "\n" ] +] + + +(* regular entries *) +let item_re = "server_port" + | "command_prefix" + | "server_address" + | "allowed_hosts" + | "debug" + | "nrpe_user" + | "nrpe_group" + | "dont_blame_nrpe" + | "command_timeout" + | "connection_timeout" + | "allow_weak_random_seed" + | "pid_file" + | "log_facility" + +let item = [ key item_re . eq . store /[^=\n\t ]+/ . nl ] + + +(* include entries + +nrpe.cfg can include more than one file or directory of files + +include=/path/to/file1.cfg +include=/path/to/file2.cfg +include_dir=/path/to/dir/ + +*) +let include = [ key "include" . + [ label "file" . eq . store /[^=\n\t ]+/ . nl ] +] +let include_dir = [ key "include_dir" . + [ label "dir" . eq . store /[^=\n\t ]+/ . nl ] +] + + +(* comments + +We can't use Util.comment because nrpe only allows comments starting at +beginning of line. + +*) +let comment = [ label "#comment" . del /^#[ \t]*/ "# " . store /([^ \t\n].*[^ \t\n]|[^ \t\n])/ . nl ] + + +(* blank lines and empty comments *) +let empty = Util.empty + + +(* final lens definition *) +let lns = ( command | item | include | include_dir | comment | empty ) * + +let filter = Util.stdexcl . + incl "/etc/nrpe.cfg" . + incl "/etc/nagios/nrpe.cfg" + +let xfm = transform lns (filter) diff --git a/lenses/tests/test_nrpe.aug b/lenses/tests/test_nrpe.aug new file mode 100644 index 0000000..9f53e78 --- /dev/null +++ b/lenses/tests/test_nrpe.aug @@ -0,0 +1,88 @@ +module Test_nrpe = + + let command = "command[foo]=bar\n" + + test Nrpe.command get command = + { "command" + { "foo" = "bar" } + } + + + let item = "nrpe_user=nagios\n" + + test Nrpe.item get item = + { "nrpe_user" = "nagios" } + + + let include = "include=/path/to/file.cfg\n" + + test Nrpe.include get include = + { "include" + { "file" = "/path/to/file.cfg" } + } + + + let comment = "# a comment\n" + + test Nrpe.comment get comment = + { "#comment" = "a comment" } + + + let empty = "# \n" + + test Nrpe.empty get empty = + { } + + + let lns = " +# +# server address: +server_address=127.0.0.1 + +nrpe_user=nagios +nrpe_group=nagios + +include=/etc/nrpe_local.cfg + +command[check_users]=/usr/lib/nagios/check_users -w 5 -c 10 +command[check_load]=/usr/lib/nagios/check_load -w 15,10,5 -c 30,25,20 +command[test_command]= foo bar + +include=/etc/nrpe/nrpe.cfg +include_dir=/etc/nrpe/cfgdir/ + +# trailing whitespaces +" + + test Nrpe.lns get lns = + { } + { } + { "#comment" = "server address:" } + { "server_address" = "127.0.0.1" } + { } + { "nrpe_user" = "nagios" } + { "nrpe_group" = "nagios" } + { } + { "include" + { "file" = "/etc/nrpe_local.cfg" } + } + { } + { "command" + { "check_users" = "/usr/lib/nagios/check_users -w 5 -c 10" } + } + { "command" + { "check_load" = "/usr/lib/nagios/check_load -w 15,10,5 -c 30,25,20" } + } + { "command" + { "test_command" = " foo bar " } + } + { } + { "include" + { "file" = "/etc/nrpe/nrpe.cfg" } + } + { "include_dir" + { "dir" = "/etc/nrpe/cfgdir/" } + } + { } + { "#comment" = "trailing whitespaces" } + -- 1.7.1 _______________________________________________ augeas-devel mailing list [email protected] https://www.redhat.com/mailman/listinfo/augeas-devel
