File: fields_info.cpp

package info (click to toggle)
falcosecurity-libs 0.1.1dev%2Bgit20220316.e5c53d64-5.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 4,732 kB
  • sloc: cpp: 55,770; ansic: 37,330; makefile: 74; sh: 13
file content (138 lines) | stat: -rw-r--r-- 3,003 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
Copyright (C) 2021 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.

*/

//
// Various helper functions to render stuff on the screen
//
#include <stdio.h>
#include <iostream>
#include <assert.h>
#include <algorithm>

#include <sinsp.h>
#include "fields_info.h"

static void list_fields_markdown(std::list<gen_event_filter_factory::filter_fieldclass_info> &fld_classes)
{
	for(auto &fld_class : fld_classes)
	{
		printf("\n## Field Class: %s\n\n", fld_class.name.c_str());
		printf("%s\n\n", fld_class.desc.c_str());
		printf("Name | Type | Description\n");
		printf(":----|:-----|:-----------\n");

		for(auto &fld_info : fld_class.fields)
		{
			// Skip fields with the EPF_TABLE_ONLY flag.
			if(fld_info.is_skippable())
			{
				continue;
			}

			printf("`%s` | %s | %s\n", fld_info.name.c_str(), fld_info.data_type.c_str(), fld_info.desc.c_str());
		}
	}
}

void list_fields(bool verbose, bool markdown)
{
	vector<const filter_check_info*> fc_plugins;
	std::list<gen_event_filter_factory::filter_fieldclass_info> fld_classes;

	sinsp::get_filtercheck_fields_info(fc_plugins);

	fld_classes = sinsp_filter_factory::check_infos_to_fieldclass_infos(fc_plugins);

	if(markdown)
	{
		list_fields_markdown(fld_classes);
	}
	else
	{
		for(auto &fld_class : fld_classes)
		{
			printf("%s\n", fld_class.as_string(verbose).c_str());
		}
	}
}

void list_events(sinsp* inspector, bool markdown)
{
	uint32_t j, k;
	string tstr;

	sinsp_evttables* einfo = inspector->get_event_info_tables();
	const struct ppm_event_info* etable = einfo->m_event_info;

	if(markdown)
	{
		printf("Falco | Dir | Event\n");
		printf(":-----|:----|:-----\n");
	}

	for(j = 0; j < PPM_EVENT_MAX; j++)
	{
		const struct ppm_event_info ei = etable[j];
		char dir = (PPME_IS_ENTER(j))? '>' : '<';

		if((ei.flags & EF_UNUSED) || (ei.flags & EF_OLD_VERSION) || (ei.category & EC_INTERNAL))
		{
			continue;
		}

		if(markdown)
		{
			if(sinsp::simple_consumer_consider_evtnum(j))
			{
				printf("Yes");
			} else {
				printf("No");
			}

			printf(" | %c | **%s**(", dir, ei.name);

			for(k = 0; k < ei.nparams; k++)
			{
				if(k != 0)
				{
					printf(", ");
				}

				printf("%s %s", param_type_to_string(ei.params[k].type),
					ei.params[k].name);
			}

			printf(")\n");
		} else
		{
			printf("%c %s(", dir, ei.name);

			for(k = 0; k < ei.nparams; k++)
			{
				if(k != 0)
				{
					printf(", ");
				}

				printf("%s %s", param_type_to_string(ei.params[k].type),
					ei.params[k].name);
			}

			printf(")\n");
		}
	}
}