summaryrefslogtreecommitdiff
path: root/rhnop-client
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2011-04-03 20:02:21 (GMT)
committerChristian Pointner <equinox@helsinki.at>2011-04-03 20:02:21 (GMT)
commit7567ead1174c33d95b4d164b1b148bec89ce005b (patch)
treeacac7c8f614825f30f79e72500f3a9c2a5b86cec /rhnop-client
parent9295f0d2cfebb5e4305f8ca1c5d69c4e6320f037 (diff)
added primary functions to nopcollectd
Diffstat (limited to 'rhnop-client')
-rwxr-xr-xrhnop-client/nopcollectd32
-rw-r--r--rhnop-client/nopcollectd.master.conf1
-rw-r--r--rhnop-client/nopcollectd.standby.conf1
3 files changed, 25 insertions, 9 deletions
diff --git a/rhnop-client/nopcollectd b/rhnop-client/nopcollectd
index 239011e..0944323 100755
--- a/rhnop-client/nopcollectd
+++ b/rhnop-client/nopcollectd
@@ -35,26 +35,40 @@ end
conffile = "nopcollectd." .. arg[1] .. ".conf"
conf = require "conf"
--- connect to server (reconnect after error)
-local sock = assert(socket.tcp())
+src_db = require "db"
+assert(src_db:init(conf.src_db, conf.src_user, conf.src_pwd, conf.src_host, conf.src_port, conf.src.table))
+
+dst_db = require "db"
+assert(dst_db:init(conf.dst_db, conf.dst_user, conf.dst_pwd, conf.dst_host, conf.dst_port, conf.dst.table))
+local sock = assert(socket.tcp())
local ret, err = sock:connect(conf.host, conf.port)
if ret == nil then
print(err)
return 1
end
-
print "connection established"
--- TODO: load all info we don't have yet
+local last = dst_db:getLastEntry()
+cur = assert(src_db:findMissingEntries(last)
+local cnt = 0
+while true do
+ local data = srd_db:getNextMissingEntry(cur)
+ if data == nil then break end
+ local ret, err = dst_db:addEntry(data)
+ if ret == nil do print(err) end
+ cnt = cnt + 1
+end
+
+print("synced " .. cnt .. " Entries")
while true do
local timestamp = sock:receive('*l')
- -- TODO: check if connection is closed
- print("received: '" .. timestamp .. "'")
-
- -- TODO: check if we already fetched that timestamp
- -- TODO: fetch info for the timestamp and insert it into local db
+ if timestamp == nil then break end
+ data = assert(src_db:getEntry(timestamp))
+ dst_db:addEntry(data)
end
+
sock:close()
+
return 0
diff --git a/rhnop-client/nopcollectd.master.conf b/rhnop-client/nopcollectd.master.conf
index 22113e6..8c353c1 100644
--- a/rhnop-client/nopcollectd.master.conf
+++ b/rhnop-client/nopcollectd.master.conf
@@ -2,6 +2,7 @@ sync_host=airplay.helsinki.at
sync_port=2345
src_db=nop
+src_table=now
src_host=airplay.helsinki.at
#src_port=3306
src_user=nopcollectd
diff --git a/rhnop-client/nopcollectd.standby.conf b/rhnop-client/nopcollectd.standby.conf
index 2597ab0..10e44fb 100644
--- a/rhnop-client/nopcollectd.standby.conf
+++ b/rhnop-client/nopcollectd.standby.conf
@@ -2,6 +2,7 @@ sync_host=airplay2.helsinki.at
sync_port=2345
src_db=nop
+src_table=now
src_host=airplay2.helsinki.at
#src_port=3306
src_user=nopcollectd