Connector for Kafka, receives items and events from server, pushes to Kafka topics
Source
func NewRouter(producer *kafka.DefaultProducer, auth string, allowedIPs *zbxnet.AllowedPeers) http.Handler {
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** This program 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 Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
package server
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net"
"net/http"
"strconv"
"strings"
"time"
"git.zabbix.com/ZT/kafka-connector/kafka"
"git.zabbix.com/ap/plugin-support/errs"
"git.zabbix.com/ap/plugin-support/log"
"git.zabbix.com/ap/plugin-support/zbxnet"
)
const (
contentType = "Content-Type"
applicationXndJSON = "application/x-ndjson"
applicationJSON = "application/json"
)
var _ http.ResponseWriter = &BufferedResponseWriter{}
// BufferedResponseWriter response writer for http handler.
type BufferedResponseWriter struct {
w http.ResponseWriter
buffer bytes.Buffer
code int
header http.Header
}
type handler struct {
authToken string
producer kafka.Producer
allowedPeers *zbxnet.AllowedPeers
}
type event struct {
EventID int `json:"eventid"`
Data string `json:"data"`
}
type item struct {
ItemID int `json:"itemid"`
Data string `json:"data"`
}