You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2020/01/17 01:11:12 UTC

[GitHub] [incubator-apisix] sshniro commented on a change in pull request #1070: Adding UDP logger plugin

sshniro commented on a change in pull request #1070: Adding UDP logger plugin
URL: https://github.com/apache/incubator-apisix/pull/1070#discussion_r367727549
 
 

 ##########
 File path: lua/apisix/plugins/udp-logger.lua
 ##########
 @@ -0,0 +1,87 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more
+-- contributor license agreements.  See the NOTICE file distributed with
+-- this work for additional information regarding copyright ownership.
+-- The ASF licenses this file to You under the Apache License, Version 2.0
+-- (the "License"); you may not use this file except in compliance with
+-- the License.  You may obtain a copy of the License at
+--
+--     http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+local core     = require("apisix.core")
+local log_util = require("apisix.plugins.log-util")
+local plugin_name = "udp-logger"
+local ngx = ngx
+
+local timer_at = ngx.timer.at
+local udp = ngx.socket.udp
+
+local schema = {
+    type = "object",
+    properties = {
+        host = {type = "string"},
+        port = {type = "number"},
+        timeout = {type = "number", minimum = 1} --default is 3 seconds
+    },
+    required = {"host", "port"}
+}
+
+
+local _M = {
+    version = 0.1,
+    priority = 400,
+    name = plugin_name,
+    schema = schema,
+}
+
+function _M.check_schema(conf)
+
+    if not conf.timeout then
+        conf.timeout = 3
+    end
+
+    return core.schema.check(schema, conf)
+end
+
+local function log(premature, conf, log_message)
+    if premature then
+        return
+    end
+
+    local sock = udp()
+    sock:settimeout(conf.timeout)
+    local ok, err = sock:setpeername(conf.host, conf.port)
+
+    if not ok then
+        core.log.error("Failed to connect to UDP server: host[", conf.host, "] port[", conf.port, "] ", err)
+        return
+    end
+
+    ok, err = sock:send(log_message)
 
 Review comment:
   @membphis as these are individual JSON messages is it okay to add a tail to the JSON string? 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services