SWIG Interface File(s)¶
The following modular SWIG 4.x interface files in interface/ wrap the C++17 ezsnmp_data_logger engine for the 4 supported target languages: Python, JavaScript (Node.js N-API), C# (.NET P/Invoke), and Go (cgo).
For more information on SWIG interface syntax, see the SWIG 4 Documentation.
Top-Level Module (ezsnmp_data_logger.i)¶
%module ezsnmp_data_logger
#ifdef SWIGPYTHON
%feature("autodoc", "2");
%feature("python:annotations", "c");
#endif
%include <stdint.i>
%include <std_string.i>
%include <std_vector.i>
%include "exceptions.i"
%include "datatypes.i"
%include "config.i"
%include "data_logger.i"
Exception Mapping (exceptions.i)¶
// SWIG exception translation across supported target languages (python, javascript, csharp, go)
%include <exception.i>
%{
#include "ezsnmp_data_logger/exceptions.h"
%}
%exception {
try {
$action
} catch (const ezsnmp_data_logger::ConfigError& e) {
SWIG_exception(SWIG_ValueError, e.what());
} catch (const ezsnmp_data_logger::SnmpError& e) {
SWIG_exception(SWIG_IOError, e.what());
} catch (const ezsnmp_data_logger::SinkError& e) {
SWIG_exception(SWIG_IOError, e.what());
} catch (const ezsnmp_data_logger::CliError& e) {
SWIG_exception(SWIG_SyntaxError, e.what());
} catch (const ezsnmp_data_logger::LoggerError& e) {
SWIG_exception(SWIG_RuntimeError, e.what());
} catch (const std::invalid_argument& e) {
SWIG_exception(SWIG_ValueError, e.what());
} catch (const std::out_of_range& e) {
SWIG_exception(SWIG_IndexError, e.what());
} catch (const std::exception& e) {
SWIG_exception(SWIG_RuntimeError, e.what());
}
}
Telemetry Datatypes (datatypes.i)¶
%{
#include "ezsnmp_data_logger/datatypes.h"
%}
%include "../include/ezsnmp_data_logger/datatypes.h"
%template(SampleVector) std::vector<ezsnmp_data_logger::Sample>;
%template(BatchVector) std::vector<ezsnmp_data_logger::Batch>;
%template(DutProbeResultVector) std::vector<ezsnmp_data_logger::DutProbeResult>;
%template(InspectRowVector) std::vector<ezsnmp_data_logger::InspectRow>;
#ifdef SWIGPYTHON
%extend ezsnmp_data_logger::Sample {
std::string __repr__() const {
return "Sample(metric_name='" + $self->metric_name + "', oid='" + $self->oid +
"', value='" + $self->display_value() + "', status=" +
std::to_string($self->status) + ")";
}
}
%extend ezsnmp_data_logger::Batch {
std::string __repr__() const {
return "Batch(dut_name='" + $self->dut_name + "', dut_ip='" + $self->dut_ip +
"', samples=" + std::to_string($self->samples.size()) + ")";
}
}
%extend ezsnmp_data_logger::LoggerStats {
std::string __repr__() const {
return $self->to_json(-1);
}
}
#endif
JSON Configuration & Validation (config.i)¶
%{
#include "ezsnmp_data_logger/config.h"
%}
%template(StringVector) std::vector<std::string>;
%include "../include/ezsnmp_data_logger/config.h"
%template(MetricConfigVector) std::vector<ezsnmp_data_logger::MetricConfig>;
%template(DutConfigVector) std::vector<ezsnmp_data_logger::DutConfig>;
%template(SinkConfigVector) std::vector<ezsnmp_data_logger::SinkConfig>;
#ifdef SWIGPYTHON
%extend ezsnmp_data_logger::LoggerConfig {
std::string __repr__() const {
return "LoggerConfig(duts=" + std::to_string($self->duts.size()) +
", sinks=" + std::to_string($self->sinks.size()) + ")";
}
}
#endif
DataLogger Engine & CLI Runner (data_logger.i)¶
%{
#include "ezsnmp_data_logger/version.h"
#include "ezsnmp_data_logger/data_logger.h"
#include "ezsnmp_data_logger/cli_runner.h"
%}
#ifdef SWIGPYTHON
%thread ezsnmp_data_logger::DataLogger::run;
%thread ezsnmp_data_logger::DataLogger::run_once;
%thread ezsnmp_data_logger::DataLogger::stop;
%thread ezsnmp_data_logger::DataLogger::probe;
%thread ezsnmp_data_logger::DataLogger::probe_json;
%thread ezsnmp_data_logger::DataLogger::request_json;
%thread ezsnmp_data_logger::DataLogger::set_json;
%thread ezsnmp_data_logger::CliRunner::run;
%thread ezsnmp_data_logger::CliRunner::execute;
#endif
%include "../include/ezsnmp_data_logger/version.h"
%include "../include/ezsnmp_data_logger/data_logger.h"
%include "../include/ezsnmp_data_logger/cli_runner.h"