System and firewall helpers
Interface addresses, monitor calls, trusted hosts, schedule days and port ranges.
System and firewall helpers
Interface addresses
The configured address of a DHCP interface is 0.0.0.0; the monitor API reports what it holds
right now:
1#include <forti_api/system.hpp>2 3for (const auto& address: fortiapi::system::interface_addresses("wan1"))4 std::cout << address.ip << "/" << address.prefix_length << "\n";
Monitor API
Read-only monitor endpoints the web GUI uses are generated with typed results, from response shapes recorded on a FortiOS 7.4.8 device (see Supported endpoints):
1#include <forti_api/gen/monitor.hpp>2 3auto now = fortiapi::monitor::system::Time::get(); // TimeResult4std::cout << now.time.value_or(0) << "\n";5auto routes = fortiapi::monitor::router::Statistics::get(Query().vdom("root")); // StatisticsResult
Attributes the device did not report while the shapes were recorded are absent; unknown attributes
are ignored. Every other monitor path and every monitor action goes through fortiapi::Monitor,
which passes JSON through. Paths are relative to monitor/:
1auto status = fortiapi::Monitor::get("system/status");2std::cout << status.value("hostname", "") << "\n";
Monitor::post(path, body) calls monitor actions; like every write, it is never retried.
API-user trusted hosts
1auto user = system::ApiUsers::get("automation");2system::trust(user, "10.0.0.0/24"); // or "10.0.0.0 255.255.255.0", or IPv6 "2001:db8::/32"3system::distrust(user, "192.168.1.0/24");4if (system::trusts(user, "10.0.0.0/24")) { /* ... */ }5system::ApiUsers::update(user); // sends the trusthost table only
Schedule days
1#include <forti_api/firewall.hpp>2using fortiapi::firewall::Weekday;3 4firewall::RecurringSchedule schedule;5schedule.name = "weekdays";6schedule.day = firewall::days({Weekday::monday, Weekday::tuesday, Weekday::wednesday,7 Weekday::thursday, Weekday::friday}); // "monday tuesday ..."8schedule.start = "08:00";9schedule.end = "18:00";10firewall::RecurringSchedules::add(schedule);
Service port ranges
1firewall::Service web;2web.name = "web-alt";3web.tcp_portrange = firewall::port_ranges({{80}, {8000, 8080}}); // "80 8000-8080"4firewall::Services::add(web);