-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Gianmatteo Palmieri <[email protected]>
- Loading branch information
Showing
3 changed files
with
173 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
/* | ||
Copyright (C) 2024 The Falco Authors. | ||
Licensed 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. | ||
*/ | ||
|
||
#include <cstring> | ||
#include <cstdio> | ||
#include <cstdlib> | ||
#include <sstream> | ||
#include <iostream> | ||
|
||
#include <driver/ppm_events_public.h> | ||
#include "test_plugins.h" | ||
|
||
struct plugin_state | ||
{ | ||
std::string lasterr; | ||
struct ss_plugin_metric metrics[2]; | ||
uint64_t count = 0; | ||
}; | ||
|
||
static const char* plugin_get_required_api_version() | ||
{ | ||
return PLUGIN_API_VERSION_STR; | ||
} | ||
|
||
static const char* plugin_get_version() | ||
{ | ||
return "0.1.0"; | ||
} | ||
|
||
static const char* plugin_get_name() | ||
{ | ||
return "sample_metrics"; | ||
} | ||
|
||
static const char* plugin_get_description() | ||
{ | ||
return "some desc"; | ||
} | ||
|
||
static const char* plugin_get_contact() | ||
{ | ||
return "some contact"; | ||
} | ||
|
||
static const char* plugin_get_parse_event_sources() | ||
{ | ||
return "[\"syscall\"]"; | ||
} | ||
|
||
static uint16_t* plugin_get_parse_event_types(uint32_t* num_types, ss_plugin_t* s) | ||
{ | ||
static uint16_t types[] = { | ||
PPME_SYSCALL_OPEN_E, | ||
//PPME_SYSCALL_OPEN_X, | ||
}; | ||
*num_types = sizeof(types) / sizeof(uint16_t); | ||
return &types[0]; | ||
} | ||
|
||
static ss_plugin_t* plugin_init(const ss_plugin_init_input* in, ss_plugin_rc* rc) | ||
{ | ||
*rc = SS_PLUGIN_SUCCESS; | ||
plugin_state *ret = new plugin_state(); | ||
|
||
ret->metrics[0].type = SS_PLUGIN_METRIC_TYPE_NON_MONOTONIC; | ||
ret->metrics[0].value_type = SS_PLUGIN_METRIC_VALUE_TYPE_U64; | ||
ret->metrics[0].value.u64 = 1234; | ||
ret->metrics[0].name = "dummy_metric"; | ||
|
||
ret->metrics[1].type = SS_PLUGIN_METRIC_TYPE_MONOTONIC; | ||
ret->metrics[1].value_type = SS_PLUGIN_METRIC_VALUE_TYPE_U64; | ||
ret->metrics[1].value.u64 = 0; | ||
ret->metrics[1].name = "evt_count"; | ||
|
||
return ret; | ||
} | ||
|
||
static void plugin_destroy(ss_plugin_t* s) | ||
{ | ||
delete ((plugin_state *) s); | ||
} | ||
|
||
static const char* plugin_get_last_error(ss_plugin_t* s) | ||
{ | ||
return ((plugin_state *) s)->lasterr.c_str(); | ||
} | ||
|
||
static ss_plugin_rc plugin_parse_event(ss_plugin_t *s, const ss_plugin_event_input *ev, const ss_plugin_event_parse_input* in) | ||
{ | ||
plugin_state *ps = (plugin_state *) s; | ||
ps->count++; | ||
ps->metrics[1].value.u64 = ps->count; | ||
|
||
return SS_PLUGIN_SUCCESS; | ||
} | ||
|
||
static ss_plugin_metric* plugin_get_metrics(ss_plugin_t *s, uint32_t *num_metrics) | ||
{ | ||
plugin_state *ps = (plugin_state *) s; | ||
|
||
*num_metrics = sizeof(ps->metrics) / sizeof(ss_plugin_metric); | ||
|
||
return ps->metrics; | ||
} | ||
|
||
void get_plugin_api_sample_metrics(plugin_api& out) | ||
{ | ||
memset(&out, 0, sizeof(plugin_api)); | ||
out.get_required_api_version = plugin_get_required_api_version; | ||
out.get_version = plugin_get_version; | ||
out.get_description = plugin_get_description; | ||
out.get_contact = plugin_get_contact; | ||
out.get_name = plugin_get_name; | ||
out.get_last_error = plugin_get_last_error; | ||
out.init = plugin_init; | ||
out.destroy = plugin_destroy; | ||
out.get_parse_event_sources = plugin_get_parse_event_sources; | ||
out.get_parse_event_types = plugin_get_parse_event_types; | ||
out.parse_event = plugin_parse_event; | ||
out.get_metrics = plugin_get_metrics; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters