Add profile, sync, reboot and explode to event notify lua script.

This commit is contained in:
Mark Crane
2014-06-10 03:23:02 +00:00
parent 65ed1518a5
commit 6b06118979

View File

@@ -16,26 +16,42 @@
--
-- The Initial Developer of the Original Code is
-- Mark J Crane <markjcrane@fusionpbx.com>
-- Copyright (C) 2013
-- Copyright (C) 2013 - 2014
-- the Initial Developer. All Rights Reserved.
--
-- Contributor(s):
-- Mark J Crane <markjcrane@fusionpbx.com>
--define explode
function explode ( seperator, str )
local pos, arr = 0, {}
for st, sp in function() return string.find( str, seperator, pos, true ) end do -- for each divider found
table.insert( arr, string.sub( str, pos, st-1 ) ) -- attach chars left of current divider
pos = sp + 1 -- jump past current divider
end
table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider
return arr
end
--usage
--luarun app.lua event_notify reboot 1003 domain.fusionpbx.com yealink
--luarun app.lua event_notify reboot 1003@domain.fusionpbx.com yealink
--set the args as variables
command = argv[2];
user = argv[3];
domain = argv[4];
profile = argv[3];
user = argv[4];
vendor = argv[5];
--get the user and domain name from the user argv user@domain
user_table = explode("@",user);
user = user_table[1];
domain = user_table[2];
--create the event notify object
local event = freeswitch.Event('NOTIFY');
--add the headers
event:addHeader('profile', 'internal');
event:addHeader('profile', profile);
event:addHeader('user', user);
event:addHeader('host', domain);
event:addHeader('content-type', 'application/simple-message-summary');
@@ -45,32 +61,47 @@
if (command == "reboot") then
event:addHeader('event-string', 'reboot=true');
end
if (command == "check_sync") then
event:addHeader('event-string', 'check-sync;reboot=false');
end
end
--grandstream
if (vendor == "grandstream") then
if (command == "reboot") then
event:addHeader('event-string', 'check-sync;reboot=true');
event:addHeader('event-string', 'reboot=true');
end
if (command == "check_sync") then
event:addHeader('event-string', 'check-sync;reboot=false');
end
end
--polycom
if (vendor == "polycom") then
if (command == "reboot") then
event:addHeader('event-string', 'check-sync;reboot=true');
event:addHeader('event-string', 'reboot=true');
end
if (command == "check_sync") then
event:addHeader('event-string', 'check-sync;reboot=false');
end
end
--yealink
if (vendor == "yealink") then
if (command == "reboot") then
event:addHeader('event-string', 'check-sync;reboot=true');
event:addHeader('event-string', 'reboot=true');
end
if (command == "check_sync") then
event:addHeader('event-string', 'check-sync;reboot=false');
end
end
--snom
if (vendor == "snom") then
if (command == "reboot") then
event:addHeader('event-string', 'check-sync;reboot=true');
event:addHeader('event-string', 'reboot=true');
end
if (command == "check_sync") then
event:addHeader('event-string', 'check-sync;reboot=false');
end
end
@@ -78,4 +109,4 @@
event:fire();
--log the event
freeswitch.consoleLog("notice", "[event_notify] command "..command.." "..user.."@"..domain.." vendor "..tostring(vendor).."\n");
freeswitch.consoleLog("notice", "[event_notify] command "..command.." "..user.."@"..domain.." vendor "..tostring(vendor).."\n");