From 7567ead1174c33d95b4d164b1b148bec89ce005b Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sun, 3 Apr 2011 20:02:21 +0000 Subject: added primary functions to nopcollectd 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 -- cgit v0.10.2