summaryrefslogtreecommitdiff
path: root/rhnop-client/nopcollectd
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/nopcollectd
parent9295f0d2cfebb5e4305f8ca1c5d69c4e6320f037 (diff)
added primary functions to nopcollectd
Diffstat (limited to 'rhnop-client/nopcollectd')
-rwxr-xr-xrhnop-client/nopcollectd32
1 files changed, 23 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