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(falco): add --version-json to print version information in json format #2331

Merged
merged 1 commit into from
Jan 10, 2023
Merged
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
19 changes: 3 additions & 16 deletions userspace/falco/app_actions/print_support.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,10 @@ application::run_result application::print_support()
support["version"] = FALCO_VERSION;

support["libs_version"] = FALCOSECURITY_LIBS_VERSION;
support["plugin_api_version"] = s->get_plugin_api_version();
support["plugin_api_version"] = application::get_plugin_api_version();

auto driver_api_version = s->get_scap_api_version();
unsigned long driver_api_major = PPM_API_VERSION_MAJOR(driver_api_version);
unsigned long driver_api_minor = PPM_API_VERSION_MINOR(driver_api_version);
unsigned long driver_api_patch = PPM_API_VERSION_PATCH(driver_api_version);
snprintf(driver_api_version_string, sizeof(driver_api_version_string), "%lu.%lu.%lu", driver_api_major, driver_api_minor, driver_api_patch);

support["driver_api_version"] = driver_api_version_string;

auto driver_schema_version = s->get_scap_schema_version();
unsigned long driver_schema_major = PPM_API_VERSION_MAJOR(driver_schema_version);
unsigned long driver_schema_minor = PPM_API_VERSION_MINOR(driver_schema_version);
unsigned long driver_schema_patch = PPM_API_VERSION_PATCH(driver_schema_version);
snprintf(driver_schema_version_string, sizeof(driver_schema_version_string), "%lu.%lu.%lu", driver_schema_major, driver_schema_minor, driver_schema_patch);

support["driver_schema_version"] = driver_schema_version_string;
support["driver_api_version"] = application::get_driver_api_version();
support["driver_schema_version"] = application::get_driver_schema_version();
support["default_driver_version"] = DRIVER_VERSION;

support["system_info"]["sysname"] = sysinfo.sysname;
Expand Down
35 changes: 23 additions & 12 deletions userspace/falco/app_actions/print_version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

#include <nlohmann/json.hpp>

#include "config_falco.h"
#include "application.h"
#include "falco_engine_version.h"
Expand All @@ -27,24 +29,33 @@ application::run_result application::print_version()
std::unique_ptr<sinsp> s(new sinsp());
printf("Falco version: %s\n", FALCO_VERSION);
printf("Libs version: %s\n", FALCOSECURITY_LIBS_VERSION);
printf("Plugin API: %s\n", s->get_plugin_api_version());
printf("Plugin API: %s\n", application::get_plugin_api_version().c_str());
printf("Engine: %d\n", FALCO_ENGINE_VERSION);

// todo(leogr): move string conversion to scap
auto driver_api_version = s->get_scap_api_version();
unsigned long driver_api_major = PPM_API_VERSION_MAJOR(driver_api_version);
unsigned long driver_api_minor = PPM_API_VERSION_MINOR(driver_api_version);
unsigned long driver_api_patch = PPM_API_VERSION_PATCH(driver_api_version);
auto driver_schema_version = s->get_scap_schema_version();
unsigned long driver_schema_major = PPM_API_VERSION_MAJOR(driver_schema_version);
unsigned long driver_schema_minor = PPM_API_VERSION_MINOR(driver_schema_version);
unsigned long driver_schema_patch = PPM_API_VERSION_PATCH(driver_schema_version);
printf("Driver:\n");
printf(" API version: %lu.%lu.%lu\n", driver_api_major, driver_api_minor, driver_api_patch);
printf(" Schema version: %lu.%lu.%lu\n", driver_schema_major, driver_schema_minor, driver_schema_patch);
printf(" API version: %s\n", application::get_driver_api_version().c_str());
printf(" Schema version: %s\n", application::get_driver_api_version().c_str());
printf(" Default driver: %s\n", DRIVER_VERSION);

return run_result::exit();
}

if(m_options.print_version_info_json)
{
nlohmann::json version_info;

version_info["falco_version"] = FALCO_VERSION;
version_info["libs_version"] = FALCOSECURITY_LIBS_VERSION;
version_info["plugin_api_version"] = application::get_plugin_api_version();
version_info["driver_api_version"] = application::get_driver_api_version();
version_info["driver_schema_version"] = application::get_driver_schema_version();
version_info["default_driver_version"] = DRIVER_VERSION;
version_info["engine_version"] = std::to_string(FALCO_ENGINE_VERSION);

printf("%s\n", version_info.dump().c_str());

return run_result::exit();
}

return run_result::ok();
}
1 change: 1 addition & 0 deletions userspace/falco/app_cmdline_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ void cmdline_options::define()
("V,validate", "Read the contents of the specified rules(s) file and exit. This option can be passed multiple times to validate multiple files.", cxxopts::value(validate_rules_filenames), "<rules_file>")
("v", "Verbose output.", cxxopts::value(verbose)->default_value("false"))
("version", "Print version number.", cxxopts::value(print_version_info)->default_value("false"))
("version-json", "Print version information in JSON format", cxxopts::value(print_version_info_json)->default_value("false"))
("page-size", "Print the system page size (may help you to choose the right syscall ring-buffer size).", cxxopts::value(print_page_size)->default_value("false"));


Expand Down
1 change: 1 addition & 0 deletions userspace/falco/app_cmdline_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class cmdline_options {
std::vector<std::string> validate_rules_filenames;
bool verbose;
bool print_version_info;
bool print_version_info_json;
bool print_page_size;
bool modern_bpf;

Expand Down
35 changes: 35 additions & 0 deletions userspace/falco/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,41 @@ class application {
return g_reopen_outputs.load(std::memory_order_seq_cst) != APP_SIGNAL_NOT_SET;
}

static inline std::string get_plugin_api_version()
{
std::unique_ptr<sinsp> s(new sinsp());
return std::string(s->get_plugin_api_version());
}

// TODO: move string conversion to scap
static inline std::string get_driver_api_version()
{
char driver_api_version_string[32];
std::unique_ptr<sinsp> s(new sinsp());

auto driver_api_version = s->get_scap_api_version();
unsigned long driver_api_major = PPM_API_VERSION_MAJOR(driver_api_version);
unsigned long driver_api_minor = PPM_API_VERSION_MINOR(driver_api_version);
unsigned long driver_api_patch = PPM_API_VERSION_PATCH(driver_api_version);

snprintf(driver_api_version_string, sizeof(driver_api_version_string), "%lu.%lu.%lu", driver_api_major, driver_api_minor, driver_api_patch);
return std::string(driver_api_version_string);
}

static inline std::string get_driver_schema_version()
{
char driver_schema_version_string[32];
std::unique_ptr<sinsp> s(new sinsp());

auto driver_schema_version = s->get_scap_schema_version();
unsigned long driver_schema_major = PPM_API_VERSION_MAJOR(driver_schema_version);
unsigned long driver_schema_minor = PPM_API_VERSION_MINOR(driver_schema_version);
unsigned long driver_schema_patch = PPM_API_VERSION_PATCH(driver_schema_version);
snprintf(driver_schema_version_string, sizeof(driver_schema_version_string), "%lu.%lu.%lu", driver_schema_major, driver_schema_minor, driver_schema_patch);

return std::string(driver_schema_version_string);
}

std::unique_ptr<state> m_state;
cmdline_options m_options;
bool m_initialized;
Expand Down