Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New module: kafka #29

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions kafka/1.0.0/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export LUA_PATH = smodule/?.lua;test/?.lua;;

.PHONY: test
test:
luajit smodule/rdkafka_test.lua
luajit smodule/producer_test.lua
158 changes: 158 additions & 0 deletions kafka/1.0.0/bmodule/main.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
<template>
<div>
<el-tabs tab-position="left" v-model="leftTab">
<el-tab-pane
name="api"
:label="locale[$i18n.locale]['api']"
class="layout-fill_vertical uk-overflow-hidden"
v-if="viewMode === 'agent'"
>
<div id="exec_actions" class="uk-margin limit-length">
<el-input placeholder="Please input" v-model="actionData" class="input-with-select">
<el-select v-model="actionName" slot="prepend" placeholder="Select">
<el-option v-for="(id, idx) in module.info.actions"
:label="id"
:value="id"
:key="idx"
></el-option>
</el-select>
<el-button @click="submitAction" slot="append"
>{{ locale[$i18n.locale]['buttonExecAction'] }}
</el-button>
</el-input>
</div>
<div class="layout-fill_vertical uk-flex uk-flex-column uk-flex-between uk-overflow-auto">
<ul>
<li :key="line" v-for="line in lines">{{ line }}</li>
</ul>
</div>
</el-tab-pane>
<el-tab-pane name="events" :label="$t('BrowserModule.Page.TabTitle.Events')">
<component
:is="components['eventsTable']"
:view-mode="viewMode"
:module-name="module.info.name"
:agent-events="eventsAPI"
:agent-modules="modulesAPI"
></component>
</el-tab-pane>
<el-tab-pane name="config" :label="$t('BrowserModule.Page.TabTitle.Config')">
<component
:is="components['agentModuleConfig']"
:view-mode="viewMode"
:module="module"
:hash="hash"
></component>
</el-tab-pane>
</el-tabs>
</div>
</template>

<script>
const name = "responder";

module.exports = {
name,
props: ["protoAPI", "hash", "module", "eventsAPI", "modulesAPI", "components", "viewMode"],
data: () => ({
leftTab: undefined,
connection: {},
actionData: '{"key1": "val1"}',
actionName: "",
lines: [],
locale: {
ru: {
api: "VX API",
buttonExecAction: "Выполнить действие",
connected: "подключен",
connError: "Ошибка подключения к серверу",
recvError: "Ошибка при выполнении",
checkError: "Ошибка при проверке данных",
actionError: "Выберите действие из списка"
},
en: {
api: "VX API",
buttonExecAction: "Exec action",
connected: "connected",
connError: "Error connection to the server",
recvError: "Error on execute",
checkError: "Error on validating action data",
actionError: "Please choose action from list"
}
}
}),
created() {
if (this.viewMode === 'agent') {
this.protoAPI.connect().then(
connection => {
const date = new Date().toLocaleTimeString();
this.connection = connection;
this.connection.subscribe(this.recvData, "data");
this.$root.NotificationsService.success(`${date} ${this.locale[this.$i18n.locale]['connected']}`);
},
error => {
this.$root.NotificationsService.error(this.locale[this.$i18n.locale]['connError']);
console.log(error);
},
);
}
},
mounted() {
this.leftTab = this.viewMode === 'agent' ? 'api' : 'events';
},
methods: {
recvData(msg) {
const date = new Date();
const date_ms = date.toLocaleTimeString() + `.${date.getMilliseconds()}`;
this.lines.push(
`${date_ms} RECV DATA: ${new TextDecoder(
"utf-8"
).decode(msg.content.data)}`
);
},
checkActionData() {
if (!this.actionData || typeof(this.actionData) !== "string"){
return false;
}
try {
const actionData = JSON.parse(this.actionData);
if (typeof(actionData) !== "object") {
return false;
}
return true;
} catch (e) {
return false;
}
},
submitAction() {
const date = new Date();
const date_ms = date.toLocaleTimeString() + `.${date.getMilliseconds()}`;
if (this.actionName === "") {
this.$root.NotificationsService.error(this.locale[this.$i18n.locale]['actionError']);
return;
}
// if (!this.checkActionData()) {
// this.$root.NotificationsService.error(this.locale[this.$i18n.locale]['checkError']);
// return;
// }
let data = JSON.stringify({
data: JSON.parse(this.actionData),
actions: [`${this.module.info.name}.${this.actionName}`]
});
this.lines.push(
`${date_ms} SEND ACTION: ${data}`
);
this.connection.sendAction(data, this.actionName);
}
}
};
</script>

<style scoped>
#exec_actions .el-select .el-input {
width: 170px;
}
.input-with-select .el-input-group__prepend {
background-color: #fff;
}
</style>
1 change: 1 addition & 0 deletions kafka/1.0.0/cmodule/args.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
33 changes: 33 additions & 0 deletions kafka/1.0.0/cmodule/main.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
local cjson = require "cjson"

local function get_server_token()
for _, agent in pairs(__agents.dump()) do
return agent.Dst
end
return nil
end

__api.add_cbs{
-- Resend the content of action to a server.
action = function(src, data, name)
data = cjson.decode(data)
data.aid = __aid
data = cjson.encode(data)
return __api.send_data_to(get_server_token(), data)
end,

-- Trick for PT WinEventLog module.
data = function(src, data)
local token = get_server_token()
local records = cjson.decode(data)
local result = true
for _, r in ipairs(records or {}) do
local data = cjson.encode{aid = __aid, data = r}
result = result and __api.send_data_to(token, data)
end
return result
end,
}

__api.await(-1)
return 'success'
38 changes: 38 additions & 0 deletions kafka/1.0.0/config/action_config_schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"additionalProperties": false,
"properties": {
"kafka_produce": {
"allOf": [
{
"$ref": "#/definitions/base.action"
},
{
"properties": {
"fields": {
"default": [],
"items": {
"type": "string"
},
"type": "array"
},
"priority": {
"default": 10,
"maximum": 10,
"minimum": 10,
"type": "integer"
}
},
"required": [
"fields",
"priority"
],
"type": "object"
}
]
}
},
"required": [
"kafka_produce"
],
"type": "object"
}
62 changes: 62 additions & 0 deletions kafka/1.0.0/config/changelog.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"1.0.1": {
"en": {
"date": "11-23-2022",
"title": "New version",
"description": " "
},
"ru": {
"date": "23.11.2022",
"title": "Новая версия",
"description": " "
}
},
"1.1.0": {
"en": {
"date": "12-20-2022",
"title": "SASL mechanism",
"description": "Support SASL mechanism"
},
"ru": {
"date": "20.12.2022",
"title": "SASL механизм",
"description": "Потдерживается SASL механизм"
}
},
"1.2.0": {
"en": {
"date": "12-20-2022",
"title": "Precompiled dependencies",
"description": "Provide librdkafka.so as a precompiled library"
},
"ru": {
"date": "20.12.2022",
"title": "Прекомпилированные зависимости",
"description": "librdkafka.so поставляется в виде прекомпилированной библиотеки"
}
},
"1.3.0": {
"en": {
"date": "12-24-2022",
"title": "Support SSL",
"description": "Support secure SSL connection to a broker"
},
"ru": {
"date": "24.12.2022",
"title": "Потдержка SSL",
"description": "Добавлена потдержка защищенного SSL подключения к брокеру"
}
},
"1.4.0": {
"en": {
"date": "12-27-2022",
"title": "Agent ID",
"description": "Enrich an event with agent ID on write"
},
"ru": {
"date": "27.12.2022",
"title": "Идентификатор агента",
"description": "Вместе с событием записывается идентификатор агента"
}
}
}
Loading