summaryrefslogtreecommitdiff
path: root/rhnop-client/nopsysstated
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2011-04-05 13:36:13 (GMT)
committerChristian Pointner <equinox@helsinki.at>2011-04-05 13:36:13 (GMT)
commit99c07fae615a1f44a2eb24eb973700931017b248 (patch)
tree15203621a8deb59824b024104c5dd37496630172 /rhnop-client/nopsysstated
parent688222650cdfb2d08c5a132c470c14e384a1ee3e (diff)
added nopsysstated
Diffstat (limited to 'rhnop-client/nopsysstated')
-rwxr-xr-xrhnop-client/nopsysstated71
1 files changed, 71 insertions, 0 deletions
diff --git a/rhnop-client/nopsysstated b/rhnop-client/nopsysstated
new file mode 100755
index 0000000..a47a0ce
--- /dev/null
+++ b/rhnop-client/nopsysstated
@@ -0,0 +1,71 @@
+#!/usr/bin/lua
+--
+-- rhnop
+--
+-- Copyright (C) 2011 Christian Pointner <equinox@helsinki.at>
+--
+-- This file is part of rhnop.
+--
+-- rhnop is free software: you can redistribute it and/or modify
+-- it under the terms of the GNU General Public License as published by
+-- the Free Software Foundation, either version 3 of the License, or
+-- any later version.
+--
+-- rhnop is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with rhnop. If not, see <http://www.gnu.org/licenses/>.
+--
+--
+-- send now and next cart# and length to nopsyncd
+-- this script should be called by the now/next macro cart
+-- the arguments should be: now# nowlen next# nextlen
+--
+
+require "socket"
+
+package.path = package.path .. ";_rhnoplibdir_/?.lua"
+db = require "db"
+
+conffile = "nopsysstated.conf"
+conf = require "conf"
+
+db = assert(db.init(conf.db_db, conf.db_user, conf.db_pwd, conf.db_host, conf.db_port, conf.db_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"
+
+local current_state, err = db:getLastSysState()
+if current_state == nil then
+ print(err)
+ return 1
+end
+print("current state according to db is " .. current_state)
+
+while true do
+ local state = sock:receive('*l')
+ if state == nil then break end
+ if state ~= current_state then
+ -- reading timestamp (milliseconds since epoch)
+ local p = assert(io.popen("/bin/date --utc '+%s %N'" , 'r'))
+ local time = assert(p:read('*l'))
+ p:close()
+ local s, ns = assert(string.match(time, "([0-9]+) ([0-9]+)"))
+ local timestamp = s .. string.format("%06d", math.floor(ns/1000))
+
+ assert(db:updateSysState(timestamp, state))
+ current_state = state
+ end
+end
+
+sock:close()
+
+return 0