Class: Thm::DataServices

Inherits:
Object
  • Object
show all
Defined in:
lib/thm/dataservices.rb

Direct Known Subclasses

Consumer, Geocoding, Geolocation, Localmachine, Producer

Defined Under Namespace

Classes: External, Geocoding, Geolocation, Safebrowsing, Trafviz

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDataServices

Returns a new instance of DataServices.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/thm/dataservices.rb', line 18

def initialize
  @autocommit = false
  @datastore = "monetdb"
  @debug = false
  @mqhost = "127.0.0.1"
  @mquser = "traffic"
  @mqpass = "dk3rbi9l"
  @mqvhost = "/"
  @dbhost = "127.0.0.1"
  @dbuser = "threatmonitor"
  @dbpass = "dk3rbi9l"
  @dbname = "threatmonitor"
  @queueprefix = "cactus" # Queue names will be come prefixed with cactus_ippacket etc ..
  # Implement tblname for table freedom
  @tblname_ippacket = "ippacket"
  @tblname_tcppacket = "tcppacket"
  @tblname_udppacket = "udppacket"
  @mqconn = Bunny.new(:hostname => "#{@mqhost}", :user => "#{@mquser}", :pass => "#{@mqpass}", :vhost => "#{@mqvhost}")
end

Instance Attribute Details

#autocommitObject

This class provides all the core functionality to the lower level DatalayerLight

Example variables

obj = Thm::Producer.new
obj.mqhost = "127.0.0.1"
obj.mquser = "test"
obj.mqpass = "setone"
obj.mqconnect
obj.dbconnect


16
17
18
# File 'lib/thm/dataservices.rb', line 16

def autocommit
  @autocommit
end

#datastoreObject

This class provides all the core functionality to the lower level DatalayerLight

Example variables

obj = Thm::Producer.new
obj.mqhost = "127.0.0.1"
obj.mquser = "test"
obj.mqpass = "setone"
obj.mqconnect
obj.dbconnect


16
17
18
# File 'lib/thm/dataservices.rb', line 16

def datastore
  @datastore
end

#dbhostObject

This class provides all the core functionality to the lower level DatalayerLight

Example variables

obj = Thm::Producer.new
obj.mqhost = "127.0.0.1"
obj.mquser = "test"
obj.mqpass = "setone"
obj.mqconnect
obj.dbconnect


16
17
18
# File 'lib/thm/dataservices.rb', line 16

def dbhost
  @dbhost
end

#dbnameObject

This class provides all the core functionality to the lower level DatalayerLight

Example variables

obj = Thm::Producer.new
obj.mqhost = "127.0.0.1"
obj.mquser = "test"
obj.mqpass = "setone"
obj.mqconnect
obj.dbconnect


16
17
18
# File 'lib/thm/dataservices.rb', line 16

def dbname
  @dbname
end

#dbpassObject

This class provides all the core functionality to the lower level DatalayerLight

Example variables

obj = Thm::Producer.new
obj.mqhost = "127.0.0.1"
obj.mquser = "test"
obj.mqpass = "setone"
obj.mqconnect
obj.dbconnect


16
17
18
# File 'lib/thm/dataservices.rb', line 16

def dbpass
  @dbpass
end

#dbuserObject

This class provides all the core functionality to the lower level DatalayerLight

Example variables

obj = Thm::Producer.new
obj.mqhost = "127.0.0.1"
obj.mquser = "test"
obj.mqpass = "setone"
obj.mqconnect
obj.dbconnect


16
17
18
# File 'lib/thm/dataservices.rb', line 16

def dbuser
  @dbuser
end

#debugObject

This class provides all the core functionality to the lower level DatalayerLight

Example variables

obj = Thm::Producer.new
obj.mqhost = "127.0.0.1"
obj.mquser = "test"
obj.mqpass = "setone"
obj.mqconnect
obj.dbconnect


16
17
18
# File 'lib/thm/dataservices.rb', line 16

def debug
  @debug
end

#mqhostObject

This class provides all the core functionality to the lower level DatalayerLight

Example variables

obj = Thm::Producer.new
obj.mqhost = "127.0.0.1"
obj.mquser = "test"
obj.mqpass = "setone"
obj.mqconnect
obj.dbconnect


16
17
18
# File 'lib/thm/dataservices.rb', line 16

def mqhost
  @mqhost
end

#mqpassObject

This class provides all the core functionality to the lower level DatalayerLight

Example variables

obj = Thm::Producer.new
obj.mqhost = "127.0.0.1"
obj.mquser = "test"
obj.mqpass = "setone"
obj.mqconnect
obj.dbconnect


16
17
18
# File 'lib/thm/dataservices.rb', line 16

def mqpass
  @mqpass
end

#mquserObject

This class provides all the core functionality to the lower level DatalayerLight

Example variables

obj = Thm::Producer.new
obj.mqhost = "127.0.0.1"
obj.mquser = "test"
obj.mqpass = "setone"
obj.mqconnect
obj.dbconnect


16
17
18
# File 'lib/thm/dataservices.rb', line 16

def mquser
  @mquser
end

#mqvhostObject

This class provides all the core functionality to the lower level DatalayerLight

Example variables

obj = Thm::Producer.new
obj.mqhost = "127.0.0.1"
obj.mquser = "test"
obj.mqpass = "setone"
obj.mqconnect
obj.dbconnect


16
17
18
# File 'lib/thm/dataservices.rb', line 16

def mqvhost
  @mqvhost
end

#queueprefixObject

This class provides all the core functionality to the lower level DatalayerLight

Example variables

obj = Thm::Producer.new
obj.mqhost = "127.0.0.1"
obj.mquser = "test"
obj.mqpass = "setone"
obj.mqconnect
obj.dbconnect


16
17
18
# File 'lib/thm/dataservices.rb', line 16

def queueprefix
  @queueprefix
end

#tblname_ippacketObject

This class provides all the core functionality to the lower level DatalayerLight

Example variables

obj = Thm::Producer.new
obj.mqhost = "127.0.0.1"
obj.mquser = "test"
obj.mqpass = "setone"
obj.mqconnect
obj.dbconnect


16
17
18
# File 'lib/thm/dataservices.rb', line 16

def tblname_ippacket
  @tblname_ippacket
end

#tblname_tcppacketObject

This class provides all the core functionality to the lower level DatalayerLight

Example variables

obj = Thm::Producer.new
obj.mqhost = "127.0.0.1"
obj.mquser = "test"
obj.mqpass = "setone"
obj.mqconnect
obj.dbconnect


16
17
18
# File 'lib/thm/dataservices.rb', line 16

def tblname_tcppacket
  @tblname_tcppacket
end

#tblname_udppacketObject

This class provides all the core functionality to the lower level DatalayerLight

Example variables

obj = Thm::Producer.new
obj.mqhost = "127.0.0.1"
obj.mquser = "test"
obj.mqpass = "setone"
obj.mqconnect
obj.dbconnect


16
17
18
# File 'lib/thm/dataservices.rb', line 16

def tblname_udppacket
  @tblname_udppacket
end

Instance Method Details

#commitObject



74
75
76
# File 'lib/thm/dataservices.rb', line 74

def commit
  @conn.commit
end

#dbconnectObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/thm/dataservices.rb', line 47

def dbconnect
  if @datastore == "mysql"
    @conn = DatalayerLight::MySQLDrv.new
    puts "Using MySQL Datasource"
  elsif @datastore == "monetdb"
    @conn = DatalayerLight::MonetDBDrv.new
    puts "Using MonetDB Datasource"
  end
  @conn.hostname = @dbhost
  @conn.username = @dbuser
  @conn.password = @dbpass
  @conn.dbname = @dbname
  @conn.debug = @debug
  @conn.autocommit = @autocommit
  begin
    @conn.connect
  rescue Errno::ECONNREFUSED
    puts "Database not running!"
    puts "Bye!"
    exit
  end
end

#mqcloseObject



43
44
45
# File 'lib/thm/dataservices.rb', line 43

def mqclose
  @conn.close
end

#mqconnectObject



38
39
40
41
# File 'lib/thm/dataservices.rb', line 38

def mqconnect
  @mqconn.start
  @ch = @mqconn.create_channel
end

#query(sql) ⇒ Object



70
71
72
# File 'lib/thm/dataservices.rb', line 70

def query(sql)
  res = @conn.query("#{sql}")
end