[augeas-devel] [PATCH] Add bbhosts module and associated test
raphink at gmail.com
raphink at gmail.com
Wed Jul 23 14:47:21 UTC 2008
# HG changeset patch
# User Raphael Pinson <raphink at gmail.com>
# Date 1216824419 -7200
# Node ID 255c6af88be56271f3a07347320fa8d31cdfc97c
# Parent c1415b2594b9b5607b61dffac5aac23a0233074f
Add bbhosts module and associated test
diff -r c1415b2594b9 -r 255c6af88be5 lenses/bbhosts.aug
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lenses/bbhosts.aug Wed Jul 23 16:46:59 2008 +0200
@@ -0,0 +1,89 @@
+(* BB-hosts module for Augeas *)
+(* Author: Raphael Pinson <raphink at gmail.com> *)
+(* *)
+(* Supported : *)
+(* *)
+(* Todo : *)
+(* *)
+
+module BBhosts =
+ autoload xfm
+
+ (* Define useful shortcuts *)
+
+ let eol = del /[ \t]*\n/ "\n"
+ let eol_no_spc = Util.del_str "\n"
+ let sep_spc = Util.del_ws_spc
+ let word = store /[^|;# \n\t]+/
+ let value_to_eol = store /[^ \t][^\n]+/
+ let ip = store /[0-9\.]+/
+ let url = store /https?:[^;,# \n\t]+/
+
+ (* Define comments and empty lines *)
+ let comment = [ label "comment" . del /#[ \t]*/ "# " . store /([^ \t\n][^\n]*)?/ . eol_no_spc ]
+ let empty = [ del /[ \t]*\n/ "" ]
+
+
+ (* Define host *)
+ let host_ip = [ label "ip" . ip ]
+ let host_fqdn = [ label "fqdn" . sep_spc . word ]
+
+ let host_test_url = [ label "url" . sep_spc . url ]
+ let host_test_cont (kw:string) = [ sep_spc . store /!?/ . key kw .
+ (Util.del_str ";" .
+ [ label "url" . word ] .
+ (Util.del_str ";" . [ label "keyword" . word ])?
+ )?
+ ]
+
+
+ let host_test_flag (kw:string) = [ sep_spc . store /!?/ . key kw ]
+
+ let host_test = host_test_cont "cont"
+ | host_test_cont "contInsecure"
+ | host_test_cont "dns"
+ | host_test_flag "noping"
+ | host_test_flag "noconn"
+ | host_test_flag "ssh"
+ | host_test_flag "smtp"
+ | host_test_flag "pop3"
+ | host_test_flag "imap2"
+ | host_test_flag "telnet"
+ | host_test_flag "BBDISPLAY"
+ | host_test_flag "BBNET"
+ | host_test_flag "BBPAGER"
+ | host_test_url
+
+
+ let host_opts = [ label "probes" . sep_spc . Util.del_str "#" . host_test* ]
+
+ let host = [ label "host" . host_ip . host_fqdn . host_opts . eol ]
+
+ (* Define group-compress and group-only *)
+ let group_compress = [ key "group-compress" . sep_spc . value_to_eol . eol_no_spc .
+ ( comment | empty | host)*
+ ]
+
+ let group_only_col = [ label "col" . word ]
+ let group_only_cols = sep_spc . group_only_col . ( Util.del_str "|" . group_only_col )*
+ let group_only = [ key "group-only" . group_only_cols . sep_spc . value_to_eol . eol_no_spc .
+ ( comment | empty | host)*
+ ]
+
+
+ (* Define page *)
+ let page_title = [ label "title" . sep_spc . value_to_eol . eol_no_spc ]
+ let page = [ key "page" . sep_spc . word . page_title .
+ ( comment | empty | host )* . ( group_compress | group_only )*
+ ]
+
+
+ (* Define lens *)
+
+ let lns = (comment | empty)* . page*
+
+ let filter = incl "/etc/bb/bb-hosts"
+ . Util.stdexcl
+
+ let xfm = transform lns filter
+
diff -r c1415b2594b9 -r 255c6af88be5 lenses/tests/test_bbhosts.aug
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lenses/tests/test_bbhosts.aug Wed Jul 23 16:46:59 2008 +0200
@@ -0,0 +1,94 @@
+module Test_bbhosts =
+
+ let conf = "
+# A comment
+
+page firstpage My first page
+
+group-compress A group
+1.2.3.4 amachine # http://url.to/monitor https://another.url/to/monitor cont;http://a.cont.url/to/monitor;wordtofind
+1.2.3.5 amachine2 # http://url.to/monitor https://another.url/to/monitor !cont;http://a.cont.url/to/monitor;wordtofind
+
+group-only dns VIP DNS
+10.50.25.48 mydnsmachine.network #
+10.50.25.49 myotherdnsmachine.network # noping noconn !ssh dns;mydnstocheck
+# a comment in a group
+
+
+page anotherpage A new page
+
+# a comment in a page
+
+group-compress My test
+192.168.0.2 myhost # https://myurl.com:1256 noconn pop3 imap2 ssh
+192.168.0.3 myhost2 # !imap2 telnet dns
+"
+
+ test BBhosts.lns get conf =
+ {}
+ { "comment" = "A comment" }
+ {}
+ { "page" = "firstpage"
+ { "title" = "My first page" }
+ {}
+ { "group-compress" = "A group"
+ { "host"
+ { "ip" = "1.2.3.4" }
+ { "fqdn" = "amachine" }
+ { "probes"
+ { "url" = "http://url.to/monitor" }
+ { "url" = "https://another.url/to/monitor" }
+ { "cont" = ""
+ { "url" = "http://a.cont.url/to/monitor" }
+ { "keyword" = "wordtofind" } } } }
+ { "host"
+ { "ip" = "1.2.3.5" }
+ { "fqdn" = "amachine2" }
+ { "probes"
+ { "url" = "http://url.to/monitor" }
+ { "url" = "https://another.url/to/monitor" }
+ { "cont" = "!"
+ { "url" = "http://a.cont.url/to/monitor" }
+ { "keyword" = "wordtofind" } } } }
+ {} }
+ { "group-only" = "VIP DNS"
+ { "col" = "dns" }
+ { "host"
+ { "ip" = "10.50.25.48" }
+ { "fqdn" = "mydnsmachine.network" }
+ { "probes" } }
+ { "host"
+ { "ip" = "10.50.25.49" }
+ { "fqdn" = "myotherdnsmachine.network" }
+ { "probes"
+ { "noping" = "" }
+ { "noconn" = "" }
+ { "ssh" = "!" }
+ { "dns" = ""
+ { "url" = "mydnstocheck" } } } }
+ { "comment" = "a comment in a group" }
+ {}
+ {} } }
+ { "page" = "anotherpage"
+ { "title" = "A new page" }
+ {}
+ { "comment" = "a comment in a page" }
+ {}
+ { "group-compress" = "My test"
+ { "host"
+ { "ip" = "192.168.0.2" }
+ { "fqdn" = "myhost" }
+ { "probes"
+ { "url" = "https://myurl.com:1256" }
+ { "noconn" = "" }
+ { "pop3" = "" }
+ { "imap2" = "" }
+ { "ssh" = "" } } }
+ { "host"
+ { "ip" = "192.168.0.3" }
+ { "fqdn" = "myhost2" }
+ { "probes"
+ { "imap2" = "!" }
+ { "telnet" = "" }
+ { "dns" = "" } } } } }
+
More information about the augeas-devel
mailing list