Class: WCC::Prog
- Inherits:
-
Object
- Object
- WCC::Prog
- Defined in:
- lib/wcc.rb
Class Method Summary collapse
-
.exit(errno) ⇒ Object
Central exit function, allows wcc a clean shutdown.
-
.load_template(name) ⇒ ERB
Attempts to read the named template file from template.d and converts it into ERB.
- .run! ⇒ Object
-
.save_template(name, raw_content) ⇒ Object
Attempts to write the given raw content to the named template file in template.d.
Class Method Details
.exit(errno) ⇒ Object
Central exit function, allows wcc a clean shutdown.
422 423 424 |
# File 'lib/wcc.rb', line 422 def self.exit(errno) Kernel::exit errno end |
.load_template(name) ⇒ ERB
Attempts to read the named template file from template.d and converts it into ERB.
394 395 396 397 398 399 400 401 402 403 |
# File 'lib/wcc.rb', line 394 def self.load_template(name) t_path = File.join(Conf[:template_dir], name) if File.exists?(t_path) WCC.logger.debug "Load template '#{name}'" t = File.open(t_path, 'r') { |f| f.read } # <> omit newline for lines starting with <% and ending in %> return ERB.new(t, 0, "<>") end nil end |
.run! ⇒ Object
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 |
# File 'lib/wcc.rb', line 347 def self.run! # make sure logger is correctly configured WCC.logger = Logger.new(STDOUT) # first use of Conf initializes it Conf.instance create_cache_dir clean_cache_dir if Conf[:clean] load_filters # stats @@stats = { 'nruns' => 1, 'nsites' => 0, 'nnotifications' => 0, 'nerrors' => 0, 'nlines' => 0, 'nhunks' => 0 } Conf.sites.each do |site| ts_old = (site) ts_new = Time.now.to_i if (ts_new-ts_old) < site.check_interval*60 ts_diff = (ts_new-ts_old)/60 WCC.logger.info "Skipping check for #{site.uri.host.to_s} due to check #{ts_diff} minute#{ts_diff == 1 ? '' : 's'} ago." next end case checkForUpdate(site) when :update WCC.logger.warn "#{site.uri.host.to_s} has an update!" when :noupdate WCC.logger.info "#{site.uri.host.to_s} is unchanged" when :error @@stats['nerrors'] += 1 end (site, ts_new) end update_stats if Conf[:stats] shut_down_notificators end |
.save_template(name, raw_content) ⇒ Object
Attempts to write the given raw content to the named template file in template.d. This should be used to create initial template files on demand and will work only when file does not already exist.
411 412 413 414 415 416 417 418 419 |
# File 'lib/wcc.rb', line 411 def self.save_template(name, raw_content) t_path = File.join(Conf[:template_dir], name) if File.exists?(t_path) WCC.logger.warn "Trying to save template '#{name}' which already exists!" return end WCC.logger.info "Save template '#{name}' to #{t_path}" File.open(t_path, 'w') { |f| f.write(raw_content) } end |