Page tree
Skip to end of metadata
Go to start of metadata

This trigger logs all the API calls made by each user. The user's customer must be given the tag DEBUG for this trigger to work. For information about how to tag a customer, see Managing Customers.

function register()
    return {
        "pre_admin_api_trigger",
        "post_admin_api_trigger",
        "pre_user_api_trigger",
        "post_user_api_trigger"
        }
end
  
function pre_admin_api_trigger(p)
  
    if(p==nil) then
        return{
            ref = "debug_pre_admin",
            name = "Debug PRE_ADMIN_API_CALL",
            description = "Trigger to log an admin api call before it is invoked.",
            triggerType = "PRE_ADMIN_API_CALL",
            triggerOptions = {"ANY"},
            includeCustomerTags = {"DEBUG"},
            api = "TRIGGER",
            version = 1,
        }
    end
    local syslog = new("syslog")
    syslog.openlog("TRIGGER", syslog.LOG_ODELAY + syslog.LOG_PID, "LOG_LOCAL2")
    local params = "PRE_ADMIN_API_CALL: "..p.triggerOption.." params: "
    for i = 1, #p.input, 1 do
        if(type(p.input[i]) == "string") then
            params = params ..", "..p.input[i]
        elseif(type(p.input[i]) == "number") then
            params = params ..", "..p.input[i]
        elseif(type(p.input[i]) == "boolean") then
            if(p.input[i]) then
                params = params ..", true"
            else
                params = params ..", false"
            end
        elseif(p.input[i] ~= nil) then
            params = params ..", "..p.input[i]:toString()
        end
    end
    params=params.." time: "..p.timeStamp
    syslog.syslog("LOG_DEBUG",params)
  
    syslog.closelog()
  
    return {exitState = "CONTINUE"}
  
end
  
function post_admin_api_trigger(p)
  
    if(p==nil) then
        return{
            ref = "debug_post_admin",
            name = "Debug POST_ADMIN_API_CALL",
            description = "Trigger to log an admin api call after it has been invoked.",
            triggerType = "POST_ADMIN_API_CALL",
            triggerOptions = {"ANY"},
            includeCustomerTags = {"DEBUG"},
            api = "TRIGGER",
            version = 1,
        }
    end
  
    local syslog = new("syslog")
    syslog.openlog("TRIGGER", syslog.LOG_ODELAY + syslog.LOG_PID, "LOG_LOCAL2")
  
    local params = "POST_ADMIN_API_CALL: "..p.triggerOption.." params: "
    for i = 1, #p.input, 1 do
        if(type(p.input[i]) == "string") then
            params = params ..", "..p.input[i]
        elseif(type(p.input[i]) == "number") then
            params = params ..", "..p.input[i]
        elseif(type(p.input[i]) == "boolean") then
            if(p.input[i]) then
                params = params ..", true"
            else
                params = params ..", false"
            end
        elseif(p.input[i] ~= nil) then
            params = params ..", "..p.input[i]:toString()
        end
    end
    params=params.." time: "..p.timeStamp
    syslog.syslog("LOG_DEBUG",params)
  
    syslog.closelog()
  
    return {exitState = "CONTINUE"}
  
end
  
function pre_user_api_trigger(p)
  
    if(p==nil) then
        return{
            ref = "debug_pre_user",
            name = "Debug PRE_USER_API_CALL",
            description = "Trigger to log an user api call before it is invoked.",
            triggerType = "PRE_USER_API_CALL",
            triggerOptions = {"fetchResource","deleteResource"},
            includeCustomerTags = {"DEBUG"},
            api = "TRIGGER",
            version = 1,
        }
    end
   
    local syslog = new("syslog")
    syslog.openlog("TRIGGER", syslog.LOG_ODELAY + syslog.LOG_PID, "LOG_LOCAL2")
  
    local params = "PRE_USER_API_CALL: "..p.triggerOption.." params: "
    for i = 1, #p.input, 1 do
        if(type(p.input[i]) == "string") then
            params = params ..", "..p.input[i]
        elseif(type(p.input[i]) == "number") then
            params = params ..", "..p.input[i]
        elseif(type(p.input[i]) == "boolean") then
            if(p.input[i]) then
                params = params ..", true"
            else
                params = params ..", false"
            end
        elseif(p.input[i] ~= nil) then
            params = params ..", "..p.input[i]:toString()
        end
    end
    params=params.." time: "..p.timeStamp
    syslog.syslog("LOG_DEBUG",params)
    syslog.closelog()
  
    return {exitState = "CONTINUE"}
  
end
  
function post_user_api_trigger(p)
  
    if(p==nil) then
        return{
            ref = "debug_post_user",
            name = "Debug POST_USER_API_CALL",
            description = "Trigger to log an user api call after it has been invoked.",
            triggerType = "POST_USER_API_CALL",
            triggerOptions = {"ANY"},
            includeCustomerTags = {"DEBUG"},
            api = "TRIGGER",
            version = 1,
        }
    end
    local syslog = new("syslog")
    syslog.openlog("TRIGGER", syslog.LOG_ODELAY + syslog.LOG_PID, "LOG_LOCAL2")
  
    local params = "POST_USER_API_CALL: "..p.triggerOption.." params: "
    for i = 1, #p.input, 1 do
        if(type(p.input[i]) == "string") then
            params = params ..", "..p.input[i]
        elseif(type(p.input[i]) == "number") then
            params = params ..", "..p.input[i]
        elseif(type(p.input[i]) == "boolean") then
            if(p.input[i]) then
                params = params ..", true"
            else
                params = params ..", false"
            end
        elseif(p.input[i] ~= nil) then
            params = params ..", "..p.input[i]:toString()
        end
    end
    params=params.." time: "..p.timeStamp
    syslog.syslog("LOG_DEBUG",params)
  
    syslog.closelog()
  
    return {exitState = "CONTINUE"}
  
end
  • No labels