Skip to content

Commit 26c4b67

Browse files
sfarouq-extchris.mvila
and
chris.mvila
authored
enh(fortinet): add option last-update (licenses) (#5399)
Refs: CTOR-1126 Co-authored-by: chris.mvila <[email protected]>
1 parent 9007170 commit 26c4b67

File tree

3 files changed

+158
-1
lines changed

3 files changed

+158
-1
lines changed

src/network/fortinet/fortigate/restapi/mode/licenses.pm

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ sub custom_expires_perfdata {
4545
);
4646
}
4747

48+
sub custom_last_update_threshold {
49+
my ($self, %options) = @_;
50+
51+
return $self->{perfdata}->threshold_check(
52+
value => floor($self->{result_values}->{last_update_seconds} / $unitdiv->{ $self->{instance_mode}->{option_results}->{unit} }),
53+
threshold => [
54+
{ label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' },
55+
{ label => 'warning-'. $self->{thlabel}, exit_litteral => 'warning' }
56+
]
57+
);
58+
}
59+
4860
sub custom_expires_threshold {
4961
my ($self, %options) = @_;
5062

@@ -95,7 +107,17 @@ sub set_counters {
95107
closure_custom_perfdata => $self->can('custom_expires_perfdata'),
96108
closure_custom_threshold_check => $self->can('custom_expires_threshold')
97109
}
110+
},
111+
{ label => 'last-update', set => {
112+
key_values => [ { name => 'last_update_seconds' }, { name => 'last_update_human' }, { name => 'name' } ],
113+
output_template => 'last_update is %s',
114+
output_use => 'last_update_human',
115+
#closure_custom_perfdata => $self->can('custom_expires_perfdata'),
116+
closure_custom_perfdata => sub { return 0; },
117+
closure_custom_threshold_check => $self->can('custom_last_update_threshold')
118+
}
98119
}
120+
99121
];
100122
}
101123

@@ -132,6 +154,14 @@ sub add_license {
132154
name => $options{name},
133155
status => $options{entry}->{status}
134156
};
157+
158+
if (defined($options{entry}->{last_update})) {
159+
$self->{licenses}->{ $options{name} }->{last_update_seconds} = time() - $options{entry}->{last_update};
160+
$self->{licenses}->{ $options{name} }->{last_update_human} = centreon::plugins::misc::change_seconds(
161+
value => $self->{licenses}->{ $options{name} }->{last_update_seconds}
162+
);
163+
}
164+
135165
if (defined($options{entry}->{expires})) {
136166
$self->{licenses}->{ $options{name} }->{expires_seconds} = $options{entry}->{expires} - time();
137167
$self->{licenses}->{ $options{name} }->{expires_seconds} = 0 if ($self->{licenses}->{ $options{name} }->{expires_seconds} < 0);
@@ -192,7 +222,7 @@ Select the time unit for the expiration thresholds. May be 's' for seconds, 'm'
192222
=item B<--warning-*> B<--critical-*>
193223
194224
Thresholds.
195-
Can be: 'expires'.
225+
Can be: 'expires', 'last-update'
196226
197227
=back
198228
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
{
2+
"uuid": "edae28cc-0d15-4208-9e84-a3bec3f4032f",
3+
"lastMigration": 32,
4+
"name": "Output api (copy)",
5+
"endpointPrefix": "",
6+
"latency": 0,
7+
"port": 3001,
8+
"hostname": "",
9+
"folders": [],
10+
"routes": [
11+
{
12+
"uuid": "fd224d5e-66c5-49dc-a1aa-c8f0cc3db291",
13+
"type": "http",
14+
"documentation": "",
15+
"method": "get",
16+
"endpoint": "api/v2/monitor/license/status/select/",
17+
"responses": [
18+
{
19+
"uuid": "700dc720-1251-4d1d-9f18-03e4fa8ffee4",
20+
"body": "{\n \"http_method\": \"GET\",\n \"results\": {\n \"fortiguard\": {\n \"type\": \"cloud_service_status\",\n \"supported\": true,\n \"connected\": true,\n \"has_updated\": true,\n \"update_server_usa\": false,\n \"next_scheduled_update\": 1731938460,\n \"scheduled_updates_enabled\": true,\n \"server_address\": \"xx.xx.xx.xx:443\",\n \"fortigate_wan_ip\": \"xx.xx.xx.xx\"\n },\n \"forticare\": {\n \"type\": \"cloud_service_status\",\n \"status\": \"registered\",\n \"registration_supported\": true,\n \"account\": \"[email protected]\",\n \"support\": {\n \"hardware\": {\n \"status\": \"licensed\",\n \"support_level\": \"Advanced HW\",\n \"expires\": 1737244800\n },\n \"enhanced\": {\n \"status\": \"licensed\",\n \"support_level\": \"Premium\",\n \"expires\": 1737244800\n }\n },\n \"company\": \"xxxxxxxxx\",\n \"industry\": \"\"\n },\n \"forticloud\": {\n \"type\": \"cloud_service_status\",\n \"status\": \"cloud_logged_out\"\n },\n \"security_rating\": {\n \"type\": \"downloaded_fds_object\",\n \"status\": \"no_license\",\n \"version\": \"0.00000\",\n \"entitlement\": \"FGSA\",\n \"last_update\": 978303600\n },\n \"antivirus\": {\n \"type\": \"downloaded_fds_object\",\n \"status\": \"expired\",\n \"version\": \"1.00000\",\n \"expires\": 1515888000,\n \"entitlement\": \"AVDB\",\n \"last_update\": 1523293620,\n \"last_update_attempt\": 1672054760,\n \"last_update_result_status\": \"update_result_not_authorized\",\n \"last_update_method_status\": \"update_method_manual\",\n \"db_status\": \"db_type_extended\",\n \"engine\": {\n \"version\": \"6.00298\",\n \"last_update\": 1709239320,\n \"last_update_attempt\": 1567573458,\n \"last_update_result_status\": \"update_result_not_authorized\",\n \"last_update_method_status\": \"update_method_manual\"\n }\n },\n \"mobile_malware\": {\n \"type\": \"downloaded_fds_object\",\n \"status\": \"expired\",\n \"version\": \"0.00000\",\n \"expires\": 1515888000,\n \"entitlement\": \"AVDB\",\n \"last_update\": 978303600,\n \"last_update_attempt\": 1672054760,\n \"last_update_result_status\": \"update_result_not_authorized\",\n \"last_update_method_status\": \"update_method_manual\"\n },\n \"ai_malware_detection\": {\n \"type\": \"downloaded_fds_object\",\n \"status\": \"expired\",\n \"version\": \"0.00000\",\n \"expires\": 1515888000,\n \"entitlement\": \"AVDB\",\n \"last_update\": 978303600\n },\n \"ips\": {\n \"type\": \"downloaded_fds_object\",\n \"status\": \"expired\",\n \"version\": \"6.00741\",\n \"expires\": 1515888000,\n \"entitlement\": \"NIDS\",\n \"last_update\": 1448933400,\n \"last_update_attempt\": 1567573458,\n \"last_update_result_status\": \"update_result_not_authorized\",\n \"last_update_method_status\": \"update_method_manual\",\n \"db_status\": \"db_type_normal\",\n \"engine\": {\n \"version\": \"7.00181\",\n \"last_update\": 1709587380,\n \"last_update_attempt\": 1567573458,\n \"last_update_result_status\": \"update_result_not_authorized\",\n \"last_update_method_status\": \"update_method_manual\"\n }\n },\n \"industrial_db\": {\n \"type\": \"downloaded_fds_object\",\n \"status\": \"no_license\",\n \"version\": \"6.00741\",\n \"entitlement\": \"ISSS\",\n \"last_update\": 1448933400\n },\n \"appctrl\": {\n \"type\": \"downloaded_fds_object\",\n \"status\": \"licensed\",\n \"version\": \"25.00592\",\n \"expires\": 1737244800,\n \"entitlement\": \"FMWR\",\n \"last_update\": 1620125365,\n \"last_update_attempt\": 1620125372,\n \"last_update_result_status\": \"update_result_no_updates\",\n \"last_update_method_status\": \"update_method_sched\"\n },\n \"internet_service_db\": {\n \"type\": \"downloaded_fds_object\",\n \"status\": \"licensed\",\n \"version\": \"7.03943\",\n \"last_update\": 1731726154,\n \"last_update_attempt\": 1731934873,\n \"last_update_result_status\": \"update_result_no_updates\",\n \"last_update_method_status\": \"update_method_sched\"\n },\n \"device_os_id\": {\n \"type\": \"downloaded_fds_object\",\n \"status\": \"licensed\",\n \"version\": \"1.00177\",\n \"expires\": 1737244800,\n \"entitlement\": \"FMWR\",\n \"last_update\": 1726887673,\n \"last_update_attempt\": 1731934873,\n \"last_update_result_status\": \"update_result_no_updates\",\n \"last_update_method_status\": \"update_method_sched\"\n },\n \"botnet_ip\": {\n \"type\": \"downloaded_fds_object\",\n \"status\": \"licensed\",\n \"version\": \"7.03943\",\n \"last_update\": 1731726154,\n \"last_update_attempt\": 1731934873,\n \"last_update_result_status\": \"update_result_no_updates\",\n \"last_update_method_status\": \"update_method_sched\"\n },\n \"botnet_domain\": {\n \"type\": \"downloaded_fds_object\",\n \"status\": \"expired\",\n \"version\": \"0.00000\",\n \"expires\": 1515888000,\n \"entitlement\": \"AVDB\",\n \"last_update\": 978303600,\n \"last_update_attempt\": 1672054760,\n \"last_update_result_status\": \"update_result_not_authorized\",\n \"last_update_method_status\": \"update_method_manual\"\n },\n \"malicious_urls\": {\n \"type\": \"downloaded_fds_object\",\n \"status\": \"expired\",\n \"version\": \"1.00001\",\n \"expires\": 1515888000,\n \"entitlement\": \"NIDS\",\n \"last_update\": 1672054760,\n \"last_update_attempt\": 1672054760,\n \"last_update_result_status\": \"update_result_success\",\n \"last_update_method_status\": \"update_method_sched\"\n },\n \"blacklisted_certificates\": {\n \"type\": \"downloaded_fds_object\",\n \"status\": \"expired\",\n \"version\": \"0.00000\",\n \"expires\": 1516147200,\n \"entitlement\": \"FURL\",\n \"last_update\": 978303600\n },\n \"web_filtering\": {\n \"type\": \"live_fortiguard_service\",\n \"status\": \"expired\",\n \"expires\": 1516147200,\n \"entitlement\": \"FURL\",\n \"category_list_version\": 9,\n \"running\": false\n },\n \"outbreak_prevention\": {\n \"type\": \"live_fortiguard_service\",\n \"status\": \"no_license\",\n \"entitlement\": \"ZHVO\"\n },\n \"antispam\": {\n \"type\": \"live_fortiguard_service\",\n \"status\": \"expired\",\n \"expires\": 1516147200,\n \"entitlement\": \"SPAM\"\n },\n \"sdwan_network_monitor\": {\n \"type\": \"live_fortiguard_service\",\n \"status\": \"no_license\",\n \"entitlement\": \"SWNM\"\n },\n \"iot_detection\": {\n \"type\": \"live_fortiguard_service\",\n \"status\": \"no_license\",\n \"entitlement\": \"IOTH\"\n },\n \"forticloud_logging\": {\n \"type\": \"live_cloud_service\",\n \"status\": \"free_license\",\n \"used_bytes\": 0,\n \"max_bytes\": 0,\n \"log_retention_days\": 7\n },\n \"forticloud_sandbox\": {\n \"type\": \"live_cloud_service\",\n \"status\": \"free_license\",\n \"expires\": 1515888000,\n \"entitlement\": \"AVDB\",\n \"files_uploaded_daily\": 0,\n \"max_files_daily\": 100\n },\n \"fortianalyzer_cloud\": {\n \"type\": \"live_cloud_service\",\n \"status\": \"no_license\",\n \"entitlement\": \"FAZC\"\n },\n \"fortianalyzer_cloud_premium\": {\n \"type\": \"live_cloud_service\",\n \"status\": \"no_license\",\n \"entitlement\": \"AFAC\"\n },\n \"fortimanager_cloud\": {\n \"type\": \"live_cloud_service\",\n \"status\": \"no_license\",\n \"entitlement\": \"FMGC\"\n },\n \"fortiipam_cloud\": {\n \"type\": \"live_cloud_service\",\n \"status\": \"no_license\",\n \"entitlement\": \"IPMC\"\n },\n \"fortisandbox_cloud\": {\n \"type\": \"live_cloud_service\",\n \"status\": \"no_license\",\n \"entitlement\": \"FSAC\"\n },\n \"fortiems_cloud\": {\n \"type\": \"account_level_live_cloud_service\",\n \"status\": \"expires_soon\",\n \"expires\": 1732838400,\n \"entitlement\": \"FCEM\"\n },\n \"fortimanager_cloud_alci\": {\n \"type\": \"account_level_live_cloud_service\",\n \"status\": \"no_license\",\n \"entitlement\": \"FMGC\"\n },\n \"fortisandbox_cloud_alci\": {\n \"type\": \"account_level_live_cloud_service\",\n \"status\": \"no_license\",\n \"entitlement\": \"FSAP\"\n },\n \"vdom\": {\n \"type\": \"platform\",\n \"can_upgrade\": false,\n \"used\": 2,\n \"max\": 10\n },\n \"sms\": {\n \"type\": \"other\",\n \"status\": \"unavailable\",\n \"used\": 0,\n \"max\": 100\n }\n },\n \"vdom\": \"root\",\n \"path\": \"license\",\n \"name\": \"status\",\n \"action\": \"select\",\n \"status\": \"success\",\n \"serial\": \"FG100E4Q17017027\",\n \"version\": \"v7.0.15\",\n \"build\": 632\n}",
21+
"latency": 0,
22+
"statusCode": 200,
23+
"label": "",
24+
"headers": [],
25+
"bodyType": "INLINE",
26+
"filePath": "",
27+
"databucketID": "",
28+
"sendFileAsBody": false,
29+
"rules": [],
30+
"rulesOperator": "OR",
31+
"disableTemplating": false,
32+
"fallbackTo404": false,
33+
"default": true,
34+
"crudKey": "id",
35+
"callbacks": []
36+
}
37+
],
38+
"responseMode": null
39+
}
40+
],
41+
"rootChildren": [
42+
{
43+
"type": "route",
44+
"uuid": "fd224d5e-66c5-49dc-a1aa-c8f0cc3db291"
45+
}
46+
],
47+
"proxyMode": false,
48+
"proxyHost": "",
49+
"proxyRemovePrefix": false,
50+
"tlsOptions": {
51+
"enabled": false,
52+
"type": "CERT",
53+
"pfxPath": "",
54+
"certPath": "",
55+
"keyPath": "",
56+
"caPath": "",
57+
"passphrase": ""
58+
},
59+
"cors": true,
60+
"headers": [
61+
{
62+
"key": "Content-Type",
63+
"value": "application/json"
64+
},
65+
{
66+
"key": "Access-Control-Allow-Origin",
67+
"value": "*"
68+
},
69+
{
70+
"key": "Access-Control-Allow-Methods",
71+
"value": "GET,POST,PUT,PATCH,DELETE,HEAD,OPTIONS"
72+
},
73+
{
74+
"key": "Access-Control-Allow-Headers",
75+
"value": "Content-Type, Origin, Accept, Authorization, Content-Length, X-Requested-With"
76+
}
77+
],
78+
"proxyReqHeaders": [
79+
{
80+
"key": "",
81+
"value": ""
82+
}
83+
],
84+
"proxyResHeaders": [
85+
{
86+
"key": "",
87+
"value": ""
88+
}
89+
],
90+
"data": [],
91+
"callbacks": []
92+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
*** Settings ***
2+
Documentation Check licenses.
3+
4+
Resource ${CURDIR}${/}..${/}..${/}..${/}..${/}resources/import.resource
5+
6+
Suite Setup Start Mockoon ${MOCKOON_JSON}
7+
Suite Teardown Stop Mockoon
8+
Test Timeout 120s
9+
10+
** Variables ***
11+
${MOCKOON_JSON} ${CURDIR}${/}License-api.json
12+
13+
${CMD} ${CENTREON_PLUGINS}
14+
... --plugin=network::fortinet::fortigate::restapi::plugin
15+
... --hostname=${HOSTNAME}
16+
... --proto='http'
17+
... --access-token=mokoon-token
18+
... --port=${APIPORT}
19+
20+
*** Test Cases ***
21+
licenses ${tc}
22+
[Tags] network fortinet fortigate restapi
23+
${command} Catenate
24+
... ${CMD}
25+
... --mode=licenses
26+
... ${extra_options}
27+
Ctn Verify Command Output ${command} ${expected_result}
28+
29+
Examples: tc extra_options expected_result --
30+
... 1 --warning-status='\\\%{name} eq /web_filtering/i' CRITICAL: License 'ai_malware_detection' status: expired - License 'antispam' status: expired - License 'antivirus' status: expired - License 'blacklisted_certificates' status: expired - License 'botnet_domain' status: expired - License 'ips' status: expired - License 'malicious_urls' status: expired - License 'mobile_malware' status: expired - License 'web_filtering' status: expired | 'ai_malware_detection#license.expires.seconds'=0s;;;0; 'antispam#license.expires.seconds'=0s;;;0; 'antivirus#license.expires.seconds'=0s;;;0; 'appctrl#license.expires.seconds'=0s;;;0; 'blacklisted_certificates#license.expires.seconds'=0s;;;0; 'botnet_domain#license.expires.seconds'=0s;;;0; 'device_os_id#license.expires.seconds'=0s;;;0; 'forticare:support:enhanced#license.expires.seconds'=0s;;;0; 'forticare:support:hardware#license.expires.seconds'=0s;;;0; 'forticloud_sandbox#license.expires.seconds'=0s;;;0; 'fortiems_cloud#license.expires.seconds'=0s;;;0; 'ips#license.expires.seconds'=0s;;;0;
31+
... 2 --critical-status='\\\%{status} =~ /unavailable/i' CRITICAL: License 'sms' status: unavailable | 'ai_malware_detection#license.expires.seconds'=0s;;;0; 'antispam#license.expires.seconds'=0s;;;0; 'antivirus#license.expires.seconds'=0s;;;0; 'appctrl#license.expires.seconds'=0s;;;0; 'blacklisted_certificates#license.expires.seconds'=0s;;;0; 'botnet_domain#license.expires.seconds'=0s;;;0; 'device_os_id#license.expires.seconds'=0s;;;0; 'forticare:support:enhanced#license.expires.seconds'=0s;;;0; 'forticare:support:hardware#license.expires.seconds'=0s;;;0; 'forticloud_sandbox#license.expires.seconds'=0s;;;0; 'fortiems_cloud#license.expires.seconds'=0s;;;0; 'ips#license.expires.seconds'=0s;;;0; 'malicious_urls#license.expires.seconds'=0s;;;0; 'mobile_malware#license.expires.seconds'=0s;;;0; 'web_filtering#license.expires.seconds'=0s;;;0;
32+
... 3 --filter-name='sms' OK: License 'sms' status: unavailable
33+
... 4 --unit='w' CRITICAL: License 'ai_malware_detection' status: expired - License 'antispam' status: expired - License 'antivirus' status: expired - License 'blacklisted_certificates' status: expired - License 'botnet_domain' status: expired - License 'ips' status: expired - License 'malicious_urls' status: expired - License 'mobile_malware' status: expired - License 'web_filtering' status: expired | 'ai_malware_detection#license.expires.weeks'=0w;;;0; 'antispam#license.expires.weeks'=0w;;;0; 'antivirus#license.expires.weeks'=0w;;;0; 'appctrl#license.expires.weeks'=0w;;;0; 'blacklisted_certificates#license.expires.weeks'=0w;;;0; 'botnet_domain#license.expires.weeks'=0w;;;0; 'device_os_id#license.expires.weeks'=0w;;;0; 'forticare:support:enhanced#license.expires.weeks'=0w;;;0; 'forticare:support:hardware#license.expires.weeks'=0w;;;0; 'forticloud_sandbox#license.expires.weeks'=0w;;;0; 'fortiems_cloud#license.expires.weeks'=0w;;;0; 'ips#license.expires.weeks'=0w;;;0; 'malicious_urls#license.expires.weeks'=0w;;;0; 'mobile_malware#license.expires.weeks'=0w;;;0; 'web_filtering#license.expires.weeks'=0w;;;0;
34+
... 5 --critical-status='' --warning-expires=0 --critical-expires=20 OK: All licenses are ok | 'ai_malware_detection#license.expires.seconds'=0s;0:0;0:20;0; 'antispam#license.expires.seconds'=0s;0:0;0:20;0; 'antivirus#license.expires.seconds'=0s;0:0;0:20;0; 'appctrl#license.expires.seconds'=0s;0:0;0:20;0; 'blacklisted_certificates#license.expires.seconds'=0s;0:0;0:20;0; 'botnet_domain#license.expires.seconds'=0s;0:0;0:20;0; 'device_os_id#license.expires.seconds'=0s;0:0;0:20;0; 'forticare:support:enhanced#license.expires.seconds'=0s;0:0;0:20;0; 'forticare:support:hardware#license.expires.seconds'=0s;0:0;0:20;0; 'forticloud_sandbox#license.expires.seconds'=0s;0:0;0:20;0; 'fortiems_cloud#license.expires.seconds'=0s;0:0;0:20;0; 'ips#license.expires.seconds'=0s;0:0;0:20;0; 'malicious_urls#license.expires.seconds'=0s;0:0;0:20;0; 'mobile_malware#license.expires.seconds'=0s;0:0;0:20;0; 'web_filtering#license.expires.seconds'=0s;0:0;0:20;0;
35+
... 6 --warning-status='' --warning-last-update=0 --critical-last-update=100 --filter-name='forticloud_sandbox' OK: License 'forticloud_sandbox' status: free_license, expires in 0 | 'forticloud_sandbox#license.expires.seconds'=0s;;;0;

0 commit comments

Comments
 (0)