summaryrefslogtreecommitdiff
path: root/noprml/noprml.lua
blob: 360087dcb2d5720e3172a8442316c403a100012a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/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
--

local queue_name = "/rhnop"

mq = require "luamq"

-- 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*1000 + math.floor(ns/1000000)

-- check arguments
if #arg < 4 then
   io.stderr:write("too few parameters\n")
   os.exit(1)
end

-- open message queue
local q, err = mq.create(queue_name, "wo")
if q == nil then
   io.stderr:write("creation of message queue failed: " .. err .. "\n")
   os.exit(1)
end

-- send out message to nopsyncd
local result, err = mq.send(q, timestamp .. " " .. arg[1] .. " " .. arg[2] .. " " .. arg[3] .. " " .. arg[4], 0)
if result == nil then
   io.stderr:write("sending message failed: " .. err .. "\n")
   os.exit(2)
end

mq.close(q)