diff --git a/README.md b/README.md index c931b41..8de3405 100755 --- a/README.md +++ b/README.md @@ -45,6 +45,9 @@ Global: * _License/Status_ * `fortigate_license_vdom_usage` * `fortigate_license_vdom_max` + * _WebUI/State_ + * `fortigate_last_reboot_seconds` + * `fortigate_last_snapshot_seconds` Per-VDOM: diff --git a/pkg/probe/probe.go b/pkg/probe/probe.go index cf942b7..09b44cd 100644 --- a/pkg/probe/probe.go +++ b/pkg/probe/probe.go @@ -132,6 +132,7 @@ func (p *ProbeCollector) Probe(ctx context.Context, target string, hc *http.Clie {"VPN/Ssl/Connections", probeVPNSsl}, {"VPN/Ssl/Stats", probeVPNSslStats}, {"VirtualWAN/HealthCheck", probeVirtualWANHealthCheck}, + {"WebUI/State", probeWebUIState}, {"Wifi/APStatus", probeWifiAPStatus}, {"Wifi/Clients", probeWifiClients}, {"Wifi/ManagedAP", probeWifiManagedAP}, diff --git a/pkg/probe/testdata/web-ui-state.jsonnet b/pkg/probe/testdata/web-ui-state.jsonnet new file mode 100644 index 0000000..b42d2bc --- /dev/null +++ b/pkg/probe/testdata/web-ui-state.jsonnet @@ -0,0 +1,343 @@ +# api/v2/monitor/web-ui/state +{ + "http_method":"GET", + "results":{ + "model_name":"FortiGate", + "model_number":"61F", + "hostname":"fortigate", + "model":"FGT61F", + "model_subtype":"", + "model_level":"low", + "admin_using_default_password":false, + "admin":{ + "name":"prometheus", + "login_name":"prometheus", + "profile":{ + "name":"prometheus", + "q_origin_key":"prometheus", + "scope":"global", + "comments":"", + "secfabgrp":"read", + "ftviewgrp":"read", + "authgrp":"read", + "sysgrp":"read", + "netgrp":"read", + "loggrp":"read", + "fwgrp":"read", + "vpngrp":"read", + "utmgrp":"read", + "wanoptgrp":"read", + "wifi":"read", + "netgrp-permission":{ + "cfg":"none", + "packet-capture":"none", + "route-cfg":"none" + }, + "sysgrp-permission":{ + "admin":"none", + "upd":"none", + "cfg":"none", + "mnt":"none" + }, + "fwgrp-permission":{ + "policy":"none", + "address":"none", + "service":"none", + "schedule":"none", + "others":"none" + }, + "loggrp-permission":{ + "config":"none", + "data-access":"none", + "report-access":"none", + "threat-weight":"none" + }, + "utmgrp-permission":{ + "antivirus":"none", + "ips":"none", + "webfilter":"none", + "emailfilter":"none", + "data-loss-prevention":"none", + "file-filter":"none", + "application-control":"none", + "icap":"none", + "voip":"none", + "waf":"none", + "dnsfilter":"none", + "endpoint-control":"none" + }, + "admintimeout-override":"disable", + "admintimeout":10, + "system-diagnostics":"enable" + }, + "global_admin":true, + "super_admin":false, + "ignore_release_overview":"", + "ignore_invalid_signature_version":"", + "dashboard_template":"", + "guest_admin":false, + "fmg_admin":false, + "sso_login_type":"none", + "remote_admin":false, + "pki_admin":false, + "vdoms":[ + "", + "main", + "root" + ], + "vdom_info":{ + "main":{ + "central_nat_enabled":true, + "transparent_mode":false, + "ngfw_mode":"profile-based", + "features":{ + "gui-icap":false, + "gui-implicit-policy":true, + "gui-dns-database":true, + "gui-load-balance":false, + "gui-multicast-policy":false, + "gui-dos-policy":false, + "gui-object-colors":true, + "gui-voip-profile":false, + "gui-ap-profile":true, + "gui-security-profile-group":false, + "gui-local-in-policy":true, + "gui-local-reports":true, + "gui-explicit-proxy":true, + "gui-dynamic-routing":true, + "gui-sslvpn-personal-bookmarks":false, + "gui-sslvpn-realms":false, + "gui-policy-based-ipsec":false, + "gui-threat-weight":true, + "gui-spamfilter":false, + "gui-file-filter":true, + "gui-application-control":true, + "gui-ips":true, + "gui-endpoint-control":true, + "gui-endpoint-control-advanced":false, + "gui-dhcp-advanced":true, + "gui-vpn":true, + "gui-wireless-controller":false, + "gui-switch-controller":false, + "gui-fortiap-split-tunneling":false, + "gui-traffic-shaping":true, + "gui-wan-load-balancing":false, + "gui-antivirus":false, + "gui-webfilter":false, + "gui-videofilter":true, + "gui-dnsfilter":true, + "gui-waf-profile":false, + "gui-advanced-policy":true, + "gui-allow-unnamed-policy":true, + "gui-email-collection":false, + "gui-multiple-interface-policy":true, + "gui-policy-disclaimer":false, + "gui-ztna":false + }, + "virtual_wire_pair_count":0, + "is_management_vdom":false, + "log_device_state":{ + "memory":{ + "is_available":true, + "is_enabled":false, + "is_default":false, + "is_ha_supported":true + }, + "disk":{ + "is_available":true, + "is_enabled":true, + "is_loggable":true, + "num_ssds_available":1, + "disabled_by_default":false, + "is_ha_supported":true, + "is_fortiview_supported":true, + "fortiview_weekly_data":false + }, + "fortianalyzer":{ + "is_available":true, + "is_enabled":false, + "overrides_global_faz":false + }, + "fortianalyzer_cloud":{ + "is_available":false, + "is_enabled":false, + "overrides_global_faz_cloud":false + }, + "forticloud":{ + "is_available":true, + "is_enabled":true, + "is_faz_cloud":false + } + }, + "log_device_default":"forticloud", + "resolve_hostnames":true + }, + "root":{ + "central_nat_enabled":false, + "transparent_mode":false, + "ngfw_mode":"profile-based", + "features":{ + "gui-icap":false, + "gui-implicit-policy":true, + "gui-dns-database":false, + "gui-load-balance":false, + "gui-multicast-policy":false, + "gui-dos-policy":false, + "gui-object-colors":true, + "gui-voip-profile":false, + "gui-ap-profile":true, + "gui-security-profile-group":false, + "gui-local-in-policy":true, + "gui-local-reports":true, + "gui-explicit-proxy":false, + "gui-dynamic-routing":true, + "gui-threat-weight":false, + "gui-spamfilter":false, + "gui-file-filter":true, + "gui-application-control":true, + "gui-ips":true, + "gui-endpoint-control":true, + "gui-endpoint-control-advanced":false, + "gui-dhcp-advanced":true, + "gui-vpn":false, + "gui-wireless-controller":false, + "gui-switch-controller":false, + "gui-fortiap-split-tunneling":false, + "gui-traffic-shaping":true, + "gui-wan-load-balancing":false, + "gui-antivirus":false, + "gui-webfilter":false, + "gui-videofilter":true, + "gui-dnsfilter":false, + "gui-waf-profile":false, + "gui-fortiextender-controller":false, + "gui-advanced-policy":true, + "gui-allow-unnamed-policy":true, + "gui-email-collection":false, + "gui-multiple-interface-policy":true, + "gui-policy-disclaimer":false, + "gui-ztna":false + }, + "virtual_wire_pair_count":0, + "is_management_vdom":true, + "log_device_state":{ + "memory":{ + "is_available":true, + "is_enabled":false, + "is_default":false, + "is_ha_supported":true + }, + "disk":{ + "is_available":true, + "is_enabled":true, + "is_loggable":true, + "num_ssds_available":1, + "disabled_by_default":false, + "is_ha_supported":true, + "is_fortiview_supported":true, + "fortiview_weekly_data":false + }, + "fortianalyzer":{ + "is_available":true, + "is_enabled":false, + "overrides_global_faz":false + }, + "fortianalyzer_cloud":{ + "is_available":false, + "is_enabled":false, + "overrides_global_faz_cloud":false + }, + "forticloud":{ + "is_available":true, + "is_enabled":true, + "is_faz_cloud":false + } + }, + "log_device_default":"forticloud", + "resolve_hostnames":true + } + } + }, + "fext_enabled":true, + "fext_vlan_mode":false, + "snapshot_utc_time":1659857566000, + "utc_last_reboot":1657116965000, + "time_zone_offset":0, + "time_zone_text":"(GMT) Greenwich Mean Time", + "time_zone_db_name":"Etc\/GMT", + "centrally_managed":false, + "fortimanager_backup_mode":false, + "fips_cc_enabled":false, + "fips_ciphers_enabled":false, + "vdom_mode":"multi-vdom", + "management_vdom":"root", + "conserve_mode":false, + "image_sign_status":"certified", + "bios_security_level":1, + "need_fs_check":false, + "carrier_mode":false, + "has_hyperscale_license":false, + "csf_enabled":false, + "csf_group_name":"", + "csf_upstream_ip":"", + "csf_sync_mode":"default", + "csf_object_sync_mode":"local", + "ha_mode":0, + "is_ha_master":1, + "ngfw_mode":"profile-based", + "forced_low_crypto":false, + "has_log_disk":true, + "has_local_config_revisions":true, + "lenc_mode":false, + "usg_mode":false, + "admin_https_redirection":true, + "config_save_mode":"automatic", + "debug_supported_daemons":[ + "node", + "httpsd", + "cmdb", + "miglogd", + "csfd", + "sslvpnd" + ], + "is_vm":false, + "theme":"jade", + "language_code":"en", + "cmgmt_override_cookie_name":"REDACTED", + "ccsrf_token_cookie_name":"REDACTED", + "file_downloading_cookie_name":"REDACTED", + "autoscale_config_rec_override_cookie_name":"REDACTED", + "initial_vdom":"", + "timeout_minutes":60, + "features":{ + "gui-ipv6":true, + "gui-replacement-message-groups":false, + "gui-local-out":false, + "gui-certificates":true, + "gui-custom-language":false, + "gui-wireless-opensecurity":false, + "gui-display-hostname":false, + "gui-fortigate-cloud-sandbox":false, + "gui-firmware-upgrade-warning":true, + "gui-allow-default-hostname":false, + "gui-forticare-registration-setup-warning":true, + "gui-cdn-usage":true, + "switch-controller":true, + "wireless-controller":true, + "fortiextender":true, + "fortitoken-cloud-service":true + }, + "date_format":'yyyy\/MM\/dd', + "date_format_device":"system", + "security_rating_result_submission":true, + "security_rating_run_on_schedule":true + }, + "vdom":"main", + "path":"web-ui", + "name":"state", + "action":"", + "status":"success", + "serial":"FGT61FT000000000", + "version":"v7.0.6", + "build": 366 +} diff --git a/pkg/probe/webui_state.go b/pkg/probe/webui_state.go new file mode 100644 index 0000000..59c28c5 --- /dev/null +++ b/pkg/probe/webui_state.go @@ -0,0 +1,45 @@ +package probe + +import ( + "log" + + "github.com/bluecmd/fortigate_exporter/pkg/http" + "github.com/prometheus/client_golang/prometheus" +) + +func probeWebUIState(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) { + var ( + mRebootTime = prometheus.NewDesc( + "fortigate_last_reboot_seconds", + "Last system reboot epoch time in seconds", + nil, nil, + ) + mSnapshotTime = prometheus.NewDesc( + "fortigate_last_snapshot_seconds", + "Last snapshot epoch time in seconds", + nil, nil, + ) + ) + + type WebUIState struct { + SnapshotUTCTime float64 `json:"snapshot_utc_time"` + UTCLastReboot float64 `json:"utc_last_reboot"` + } + + type webuiState struct { + Results WebUIState + } + + var state webuiState + + if err := c.Get("api/v2/monitor/web-ui/state", "", &state); err != nil { + log.Printf("Error: %v", err) + return nil, false + } + + m := []prometheus.Metric{ + prometheus.MustNewConstMetric(mRebootTime, prometheus.GaugeValue, state.Results.UTCLastReboot/1000), + prometheus.MustNewConstMetric(mSnapshotTime, prometheus.GaugeValue, state.Results.SnapshotUTCTime/1000), + } + return m, true +} diff --git a/pkg/probe/webui_state_test.go b/pkg/probe/webui_state_test.go new file mode 100755 index 0000000..53450d3 --- /dev/null +++ b/pkg/probe/webui_state_test.go @@ -0,0 +1,31 @@ +package probe + +import ( + "strings" + "testing" + + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/testutil" +) + +func TestWebUIState(t *testing.T) { + c := newFakeClient() + c.prepare("api/v2/monitor/web-ui/state", "testdata/web-ui-state.jsonnet") + r := prometheus.NewPedanticRegistry() + if !testProbe(probeWebUIState, c, r) { + t.Errorf("probeWebUIState() returned non-success") + } + + em := ` + # HELP fortigate_last_reboot_seconds Last system reboot epoch time in seconds + # TYPE fortigate_last_reboot_seconds gauge + fortigate_last_reboot_seconds 1.657116965e+09 + # HELP fortigate_last_snapshot_seconds Last snapshot epoch time in seconds + # TYPE fortigate_last_snapshot_seconds gauge + fortigate_last_snapshot_seconds 1.659857566e+09 + ` + + if err := testutil.GatherAndCompare(r, strings.NewReader(em)); err != nil { + t.Fatalf("metric compare: err %v", err) + } +}