Class: SyslogRef

Inherits:
Object
  • Object
show all
Defined in:
lib/monitor/server/syslog/syslog_ref.rb

Constant Summary collapse

TABLENAME =
'syslog_ref'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(n, descr, re) ⇒ SyslogRef

end global management###############



99
100
101
102
103
104
105
106
# File 'lib/monitor/server/syslog/syslog_ref.rb', line 99

def initialize (n, descr, re)
	#name is the identifier, it must be uniq
     @name=n
     @description=descr
	#here value is a regexp
     @value=Regexp.new(re)
	@nb_use=0
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



2
3
4
# File 'lib/monitor/server/syslog/syslog_ref.rb', line 2

def description
  @description
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/monitor/server/syslog/syslog_ref.rb', line 2

def name
  @name
end

Class Method Details

.add_syslog_ref(n, descr, calc) ⇒ Object

return true if deleted otherwise false



11
12
13
14
15
16
17
# File 'lib/monitor/server/syslog/syslog_ref.rb', line 11

def SyslogRef::add_syslog_ref(n, descr, calc)
	if $syslog_refs[n] == nil
		$syslog_refs[n] = SyslogRef.new(n, descr, calc)
		return true
	end
	return false
end

.del_syslog_ref(n) ⇒ Object

delete an syslog_ref return true is entry delete otherwise false



23
24
25
26
27
28
29
# File 'lib/monitor/server/syslog/syslog_ref.rb', line 23

def SyslogRef::del_syslog_ref(n)
	if !$syslog_refs[n].used?()
		$syslog_refs.delete(n)
		return true
	end
	return false
end

.get_syslog_refs_nameObject

return a table of all syslogref name



86
87
88
89
90
91
92
# File 'lib/monitor/server/syslog/syslog_ref.rb', line 86

def SyslogRef::get_syslog_refs_name()
	name_t=[]
	$syslog_refs.each_key {|name|
		name_t.push name
	}
	return name_t
end

.read_db_syslogrefObject



55
56
57
58
59
60
61
62
63
# File 'lib/monitor/server/syslog/syslog_ref.rb', line 55

def SyslogRef::read_db_syslogref()
	if defined?($db) && ($db !=nil)
		db_select_all_prp(TABLENAME).execute do |rs|
			rs.each do |name, description, value|
				add_syslog_ref(name,description,value)
			end
		end
	end
end

.read_syslogref_conf_file(fic = SYSLOGREFS_CONF_FILE) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/monitor/server/syslog/syslog_ref.rb', line 65

def SyslogRef::read_syslogref_conf_file(fic=SYSLOGREFS_CONF_FILE)
	field_separator='~'
	if FileTest.exist?(fic)
		fic = File.new(fic,'r')
		lign=fic.gets
		while lign
			lign_t = lign.split(field_separator)
			if lign_t.size() == 3
				add_syslog_ref(lign_t[0],lign_t[1],lign_t[2].chomp())
			end
			lign=fic.gets
		end
		fic.close
	else
		puts "syslogrefs conf file not found"
	end
end

.syslog_ref_exist?(name) ⇒ Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/monitor/server/syslog/syslog_ref.rb', line 94

def SyslogRef::syslog_ref_exist?(name)
	return $syslog_refs[name] != nil
end

.write_db_syslogrefObject



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/monitor/server/syslog/syslog_ref.rb', line 31

def  SyslogRef::write_db_syslogref()
	if defined?($db) && ($db !=nil)
		$db.transaction
		db_delete_all_prp(TABLENAME).execute()
		stmt=db_insert_ref_prp(TABLENAME)
		$syslog_refs.each_value do |syslog_ref|
			stmt.execute(syslog_ref.name, syslog_ref.description, syslog_ref.value.source)
		end
		$db.commit
	end
end

.write_syslogref_conf_file(fic_name = SYSLOGREFS_CONF_FILE) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/monitor/server/syslog/syslog_ref.rb', line 43

def SyslogRef::write_syslogref_conf_file(fic_name=SYSLOGREFS_CONF_FILE)
 	   field_separator='~'
  		fic=Tempfile.new(File.basename(fic_name))
		$syslog_refs.each_value do |syslog_ref|
			fic.puts "#{syslog_ref.name}#{field_separator}#{syslog_ref.description}#{field_separator}#{syslog_ref.value.source}"
		end
		fic.close()
		if !FileUtils.move(fic.path, fic_name)
			$log.error("Can not save syslog ref conf file")
		end
end

Instance Method Details

#add_useObject



108
109
110
# File 'lib/monitor/server/syslog/syslog_ref.rb', line 108

def add_use()
	@nb_use+=1
end

#del_useObject



112
113
114
# File 'lib/monitor/server/syslog/syslog_ref.rb', line 112

def del_use()
	@nb_use-=1
end

#get_regexObject



124
125
126
# File 'lib/monitor/server/syslog/syslog_ref.rb', line 124

def get_regex()
	return @value
end

#set_value(re) ⇒ Object



132
133
134
# File 'lib/monitor/server/syslog/syslog_ref.rb', line 132

def set_value(re)
	 @value=Regexp.new(re)
end

#to_strObject



120
121
122
# File 'lib/monitor/server/syslog/syslog_ref.rb', line 120

def to_str()
	print "SyslogRef: ", @name, " ", @description, " ", @value
end

#used?Boolean

Returns:

  • (Boolean)


116
117
118
# File 'lib/monitor/server/syslog/syslog_ref.rb', line 116

def used?()
	return @nb_use>0 
end

#valueObject



128
129
130
# File 'lib/monitor/server/syslog/syslog_ref.rb', line 128

def value()
	return @value
end