]>
git.immae.eu Git - perso/Immae/Projets/Ruby/Monitor.git/blob - ini_read.rb
8 options
= OpenStruct
.new()
11 opt_parser
= OptionParser
.new() do |opts
|
13 opts
.banner
= "Usage: monitor [options]"
16 opts
.on( '-f', "-f ini_file", "chose a different initialization file") do |ini
|
20 opt_parser
.parse!
(args
)
27 attr_reader(:global,:sections)
29 # attr_accessor :global
31 options
= OptParse
.new().parse(ARGV)
32 find_ini(options
.inifile
)
37 def find_ini(option_inifile
)
38 if(not option_inifile
.nil?)
39 @inifile = option_inifile
40 elsif(ENV.has_key
?('MONITOR_RC'))
41 @inifile = ENV['MONITOR_RC']
42 elsif(Process
.uid
== 0)
43 @inifile = "/etc/monitor.rc"
45 @inifile = ENV['HOME']+
"/.monitorrc"
50 @config = IniFile
.load(@inifile, :default=>'global')
52 puts
"Initialization file not found or not readable"
64 @config.each_section
do |section
|
65 sec
= @config[section
]
66 if(section
== "global")
69 if(not sec
.has_key
?('Type'))
70 puts
"Section incomplete, ignored: "+ section
72 elsif(not sec
.has_key
?('Command'))
73 puts
"Section incomplete, ignored: "+ section
76 if(sec
['Type'] == "continuous")
77 if(not sec
.has_key
?('Buffer'))
81 if(sec
['Type'] == "oneshot")
82 if(not sec
.has_key
?('Periodic'))
86 @sections[section
] = sec