sensu-plugins-azurerm 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +21 -0
- data/README.md +278 -7
- data/bin/check-azurerm-core-usage.rb +37 -40
- data/bin/check-azurerm-cores-d-usage.rb +121 -0
- data/bin/check-azurerm-cores-ds-usage.rb +121 -0
- data/bin/check-azurerm-cores-dsv2-usage.rb +121 -0
- data/bin/check-azurerm-cores-dv2-usage.rb +121 -0
- data/bin/check-azurerm-cores-f-usage.rb +121 -0
- data/bin/check-azurerm-cores-fs-usage.rb +121 -0
- data/bin/check-azurerm-load-balancers-usage.rb +121 -0
- data/bin/check-azurerm-network-interfaces-usage.rb +121 -0
- data/bin/check-azurerm-network-security-groups-usage.rb +121 -0
- data/bin/check-azurerm-public-ip-addresses-usage.rb +121 -0
- data/bin/check-azurerm-route-tables-usage.rb +121 -0
- data/bin/check-azurerm-static-public-ip-addresses-usage.rb +121 -0
- data/bin/check-azurerm-virtual-machines-usage.rb +37 -40
- data/bin/check-azurerm-virtual-network-gateway-connected.rb +31 -34
- data/bin/check-azurerm-virtual-network-gateway-failure-connected.rb +51 -54
- data/bin/check-azurerm-virtual-networks-usage.rb +121 -0
- data/bin/metric-azurerm-service-bus-subscription-message-count.rb +39 -42
- data/bin/metric-azurerm-virtual-network-gateway-usage.rb +40 -43
- data/lib/sensu-plugins-azurerm.rb +1 -0
- data/lib/sensu-plugins-azurerm/common.rb +10 -0
- data/lib/sensu-plugins-azurerm/compute_usage.rb +3 -13
- data/lib/sensu-plugins-azurerm/network_usage.rb +12 -5
- data/lib/sensu-plugins-azurerm/servicebus_usage.rb +3 -6
- data/lib/sensu-plugins-azurerm/version.rb +1 -1
- metadata +60 -33
@@ -0,0 +1,121 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# check-azurerm-network-security-groups-usage
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# This plugin checks the number of Network Security Groups allocated and available in a Region in Azure.
|
7
|
+
# Warning and Critical Percentage thresholds may be set as needed.
|
8
|
+
#
|
9
|
+
# OUTPUT:
|
10
|
+
# plain-text
|
11
|
+
#
|
12
|
+
# PLATFORMS:
|
13
|
+
# Linux
|
14
|
+
#
|
15
|
+
# DEPENDENCIES:
|
16
|
+
# gem: azure_mgmt_network
|
17
|
+
# gem: sensu-plugin
|
18
|
+
#
|
19
|
+
# USAGE:
|
20
|
+
# ./check-azurerm-network-security-groups-usage.rb -l "westeurope" -w 80 -c 90
|
21
|
+
#
|
22
|
+
# ./check-azurerm-network-security-groups-usage.rb -t "00000000-0000-0000-0000-000000000000"
|
23
|
+
# -c "00000000-0000-0000-0000-000000000000"
|
24
|
+
# -S "00000000-0000-0000-0000-000000000000"
|
25
|
+
# -s "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234"
|
26
|
+
# -l "eastus2" -w 80 -c 90
|
27
|
+
#
|
28
|
+
# ./check-azurerm-network-security-groups-usage.rb -tenant "00000000-0000-0000-0000-000000000000"
|
29
|
+
# -client_id "00000000-0000-0000-0000-000000000000"
|
30
|
+
# -client_secret "00000000-0000-0000-0000-000000000000"
|
31
|
+
# -subscription "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234"
|
32
|
+
# -location "westeurope"
|
33
|
+
# -warning_percentage 80
|
34
|
+
# -critical_percentage 90
|
35
|
+
#
|
36
|
+
# NOTES:
|
37
|
+
#
|
38
|
+
# LICENSE:
|
39
|
+
# Tom Harvey
|
40
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
41
|
+
# for details.
|
42
|
+
#
|
43
|
+
|
44
|
+
require 'azure_mgmt_network'
|
45
|
+
require 'sensu-plugin/check/cli'
|
46
|
+
require 'sensu-plugins-azurerm'
|
47
|
+
|
48
|
+
class CheckAzureRMNetworkSecurityGroupsUsage < Sensu::Plugin::Check::CLI
|
49
|
+
include SensuPluginsAzureRM
|
50
|
+
|
51
|
+
option :tenant_id,
|
52
|
+
description: 'ARM Tenant ID. Either set ENV[\'ARM_TENANT_ID\'] or provide it as an option',
|
53
|
+
short: '-t ID',
|
54
|
+
long: '--tenant ID',
|
55
|
+
default: ENV['ARM_TENANT_ID'] # TODO: can we pull these out from the Check too?
|
56
|
+
|
57
|
+
option :client_id,
|
58
|
+
description: 'ARM Client ID. Either set ENV[\'ARM_CLIENT_ID\'] or provide it as an option',
|
59
|
+
short: '-c ID',
|
60
|
+
long: '--client ID',
|
61
|
+
default: ENV['ARM_CLIENT_ID']
|
62
|
+
|
63
|
+
option :client_secret,
|
64
|
+
description: 'ARM Client Secret. Either set ENV[\'ARM_CLIENT_SECRET\'] or provide it as an option',
|
65
|
+
short: '-s SECRET',
|
66
|
+
long: '--clientSecret SECRET',
|
67
|
+
default: ENV['ARM_CLIENT_SECRET']
|
68
|
+
|
69
|
+
option :subscription_id,
|
70
|
+
description: 'ARM Subscription ID',
|
71
|
+
short: '-S ID',
|
72
|
+
long: '--subscription ID',
|
73
|
+
default: ENV['ARM_SUBSCRIPTION_ID']
|
74
|
+
|
75
|
+
option :location,
|
76
|
+
description: 'Azure Location (e.g. westeurope/eastus2)',
|
77
|
+
short: '-l LOCATION',
|
78
|
+
long: '--location LOCATION'
|
79
|
+
|
80
|
+
option :warning_percentage,
|
81
|
+
description: 'Warning Percentage threshold for filter',
|
82
|
+
short: '-w PERCENTAGE',
|
83
|
+
long: '--warning PERCENTAGE'
|
84
|
+
|
85
|
+
option :critical_percentage,
|
86
|
+
description: 'Critical Percentage threshold for filter',
|
87
|
+
short: '-c PERCENTAGE',
|
88
|
+
long: '--critical PERCENTAGE'
|
89
|
+
|
90
|
+
def run
|
91
|
+
tenant_id = config[:tenant_id]
|
92
|
+
client_id = config[:client_id]
|
93
|
+
client_secret = config[:client_secret]
|
94
|
+
subscription_id = config[:subscription_id]
|
95
|
+
location = config[:location]
|
96
|
+
|
97
|
+
usage_client = NetworkUsage.new.build_usage_client(tenant_id, client_id, client_secret, subscription_id)
|
98
|
+
result = Common.new.retrieve_usage_stats(usage_client, location, 'NetworkSecurityGroups')
|
99
|
+
|
100
|
+
current_usage = result.current_value
|
101
|
+
allowance = result.limit
|
102
|
+
critical_percentage = config[:critical_percentage].to_f
|
103
|
+
warning_percentage = config[:warning_percentage].to_f
|
104
|
+
|
105
|
+
message = "Current usage: #{current_usage} of #{allowance} Network Security Groups"
|
106
|
+
|
107
|
+
percentage_used = (current_usage.to_f / allowance.to_f) * 100
|
108
|
+
|
109
|
+
if percentage_used >= critical_percentage
|
110
|
+
critical message
|
111
|
+
elsif percentage_used >= warning_percentage
|
112
|
+
warning message
|
113
|
+
else
|
114
|
+
ok message
|
115
|
+
end
|
116
|
+
|
117
|
+
rescue => e
|
118
|
+
puts "Error: exception: #{e}"
|
119
|
+
critical
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# check-azurerm-public-ip-addresses-usage
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# This plugin checks the number of Public IP Addresses allocated and available in a Region in Azure.
|
7
|
+
# Warning and Critical Percentage thresholds may be set as needed.
|
8
|
+
#
|
9
|
+
# OUTPUT:
|
10
|
+
# plain-text
|
11
|
+
#
|
12
|
+
# PLATFORMS:
|
13
|
+
# Linux
|
14
|
+
#
|
15
|
+
# DEPENDENCIES:
|
16
|
+
# gem: azure_mgmt_network
|
17
|
+
# gem: sensu-plugin
|
18
|
+
#
|
19
|
+
# USAGE:
|
20
|
+
# ./check-azurerm-public-ip-addresses-usage.rb -l "westeurope" -w 80 -c 90
|
21
|
+
#
|
22
|
+
# ./check-azurerm-public-ip-addresses-usage.rb -t "00000000-0000-0000-0000-000000000000"
|
23
|
+
# -c "00000000-0000-0000-0000-000000000000"
|
24
|
+
# -S "00000000-0000-0000-0000-000000000000"
|
25
|
+
# -s "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234"
|
26
|
+
# -l "eastus2" -w 80 -c 90
|
27
|
+
#
|
28
|
+
# ./check-azurerm-public-ip-addresses-usage.rb -tenant "00000000-0000-0000-0000-000000000000"
|
29
|
+
# -client_id "00000000-0000-0000-0000-000000000000"
|
30
|
+
# -client_secret "00000000-0000-0000-0000-000000000000"
|
31
|
+
# -subscription "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234"
|
32
|
+
# -location "westeurope"
|
33
|
+
# -warning_percentage 80
|
34
|
+
# -critical_percentage 90
|
35
|
+
#
|
36
|
+
# NOTES:
|
37
|
+
#
|
38
|
+
# LICENSE:
|
39
|
+
# Tom Harvey
|
40
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
41
|
+
# for details.
|
42
|
+
#
|
43
|
+
|
44
|
+
require 'azure_mgmt_network'
|
45
|
+
require 'sensu-plugin/check/cli'
|
46
|
+
require 'sensu-plugins-azurerm'
|
47
|
+
|
48
|
+
class CheckAzureRMPublicIPAddressesUsage < Sensu::Plugin::Check::CLI
|
49
|
+
include SensuPluginsAzureRM
|
50
|
+
|
51
|
+
option :tenant_id,
|
52
|
+
description: 'ARM Tenant ID. Either set ENV[\'ARM_TENANT_ID\'] or provide it as an option',
|
53
|
+
short: '-t ID',
|
54
|
+
long: '--tenant ID',
|
55
|
+
default: ENV['ARM_TENANT_ID'] # TODO: can we pull these out from the Check too?
|
56
|
+
|
57
|
+
option :client_id,
|
58
|
+
description: 'ARM Client ID. Either set ENV[\'ARM_CLIENT_ID\'] or provide it as an option',
|
59
|
+
short: '-c ID',
|
60
|
+
long: '--client ID',
|
61
|
+
default: ENV['ARM_CLIENT_ID']
|
62
|
+
|
63
|
+
option :client_secret,
|
64
|
+
description: 'ARM Client Secret. Either set ENV[\'ARM_CLIENT_SECRET\'] or provide it as an option',
|
65
|
+
short: '-s SECRET',
|
66
|
+
long: '--clientSecret SECRET',
|
67
|
+
default: ENV['ARM_CLIENT_SECRET']
|
68
|
+
|
69
|
+
option :subscription_id,
|
70
|
+
description: 'ARM Subscription ID',
|
71
|
+
short: '-S ID',
|
72
|
+
long: '--subscription ID',
|
73
|
+
default: ENV['ARM_SUBSCRIPTION_ID']
|
74
|
+
|
75
|
+
option :location,
|
76
|
+
description: 'Azure Location (e.g. westeurope/eastus2)',
|
77
|
+
short: '-l LOCATION',
|
78
|
+
long: '--location LOCATION'
|
79
|
+
|
80
|
+
option :warning_percentage,
|
81
|
+
description: 'Warning Percentage threshold for filter',
|
82
|
+
short: '-w PERCENTAGE',
|
83
|
+
long: '--warning PERCENTAGE'
|
84
|
+
|
85
|
+
option :critical_percentage,
|
86
|
+
description: 'Critical Percentage threshold for filter',
|
87
|
+
short: '-c PERCENTAGE',
|
88
|
+
long: '--critical PERCENTAGE'
|
89
|
+
|
90
|
+
def run
|
91
|
+
tenant_id = config[:tenant_id]
|
92
|
+
client_id = config[:client_id]
|
93
|
+
client_secret = config[:client_secret]
|
94
|
+
subscription_id = config[:subscription_id]
|
95
|
+
location = config[:location]
|
96
|
+
|
97
|
+
usage_client = NetworkUsage.new.build_usage_client(tenant_id, client_id, client_secret, subscription_id)
|
98
|
+
result = Common.new.retrieve_usage_stats(usage_client, location, 'PublicIPAddresses')
|
99
|
+
|
100
|
+
current_usage = result.current_value
|
101
|
+
allowance = result.limit
|
102
|
+
critical_percentage = config[:critical_percentage].to_f
|
103
|
+
warning_percentage = config[:warning_percentage].to_f
|
104
|
+
|
105
|
+
message = "Current usage: #{current_usage} of #{allowance} Public IP Addresses"
|
106
|
+
|
107
|
+
percentage_used = (current_usage.to_f / allowance.to_f) * 100
|
108
|
+
|
109
|
+
if percentage_used >= critical_percentage
|
110
|
+
critical message
|
111
|
+
elsif percentage_used >= warning_percentage
|
112
|
+
warning message
|
113
|
+
else
|
114
|
+
ok message
|
115
|
+
end
|
116
|
+
|
117
|
+
rescue => e
|
118
|
+
puts "Error: exception: #{e}"
|
119
|
+
critical
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# check-azurerm-route-tables-usage
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# This plugin checks the number of Route Tables allocated and available in a Region in Azure.
|
7
|
+
# Warning and Critical Percentage thresholds may be set as needed.
|
8
|
+
#
|
9
|
+
# OUTPUT:
|
10
|
+
# plain-text
|
11
|
+
#
|
12
|
+
# PLATFORMS:
|
13
|
+
# Linux
|
14
|
+
#
|
15
|
+
# DEPENDENCIES:
|
16
|
+
# gem: azure_mgmt_network
|
17
|
+
# gem: sensu-plugin
|
18
|
+
#
|
19
|
+
# USAGE:
|
20
|
+
# ./check-azurerm-route-tables-usage.rb -l "westeurope" -w 80 -c 90
|
21
|
+
#
|
22
|
+
# ./check-azurerm-route-tables-usage.rb -t "00000000-0000-0000-0000-000000000000"
|
23
|
+
# -c "00000000-0000-0000-0000-000000000000"
|
24
|
+
# -S "00000000-0000-0000-0000-000000000000"
|
25
|
+
# -s "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234"
|
26
|
+
# -l "eastus2" -w 80 -c 90
|
27
|
+
#
|
28
|
+
# ./check-azurerm-route-tables-usage.rb -tenant "00000000-0000-0000-0000-000000000000"
|
29
|
+
# -client_id "00000000-0000-0000-0000-000000000000"
|
30
|
+
# -client_secret "00000000-0000-0000-0000-000000000000"
|
31
|
+
# -subscription "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234"
|
32
|
+
# -location "westeurope"
|
33
|
+
# -warning_percentage 80
|
34
|
+
# -critical_percentage 90
|
35
|
+
#
|
36
|
+
# NOTES:
|
37
|
+
#
|
38
|
+
# LICENSE:
|
39
|
+
# Tom Harvey
|
40
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
41
|
+
# for details.
|
42
|
+
#
|
43
|
+
|
44
|
+
require 'azure_mgmt_network'
|
45
|
+
require 'sensu-plugin/check/cli'
|
46
|
+
require 'sensu-plugins-azurerm'
|
47
|
+
|
48
|
+
class CheckAzureRMRouteTablesUsage < Sensu::Plugin::Check::CLI
|
49
|
+
include SensuPluginsAzureRM
|
50
|
+
|
51
|
+
option :tenant_id,
|
52
|
+
description: 'ARM Tenant ID. Either set ENV[\'ARM_TENANT_ID\'] or provide it as an option',
|
53
|
+
short: '-t ID',
|
54
|
+
long: '--tenant ID',
|
55
|
+
default: ENV['ARM_TENANT_ID'] # TODO: can we pull these out from the Check too?
|
56
|
+
|
57
|
+
option :client_id,
|
58
|
+
description: 'ARM Client ID. Either set ENV[\'ARM_CLIENT_ID\'] or provide it as an option',
|
59
|
+
short: '-c ID',
|
60
|
+
long: '--client ID',
|
61
|
+
default: ENV['ARM_CLIENT_ID']
|
62
|
+
|
63
|
+
option :client_secret,
|
64
|
+
description: 'ARM Client Secret. Either set ENV[\'ARM_CLIENT_SECRET\'] or provide it as an option',
|
65
|
+
short: '-s SECRET',
|
66
|
+
long: '--clientSecret SECRET',
|
67
|
+
default: ENV['ARM_CLIENT_SECRET']
|
68
|
+
|
69
|
+
option :subscription_id,
|
70
|
+
description: 'ARM Subscription ID',
|
71
|
+
short: '-S ID',
|
72
|
+
long: '--subscription ID',
|
73
|
+
default: ENV['ARM_SUBSCRIPTION_ID']
|
74
|
+
|
75
|
+
option :location,
|
76
|
+
description: 'Azure Location (e.g. westeurope/eastus2)',
|
77
|
+
short: '-l LOCATION',
|
78
|
+
long: '--location LOCATION'
|
79
|
+
|
80
|
+
option :warning_percentage,
|
81
|
+
description: 'Warning Percentage threshold for filter',
|
82
|
+
short: '-w PERCENTAGE',
|
83
|
+
long: '--warning PERCENTAGE'
|
84
|
+
|
85
|
+
option :critical_percentage,
|
86
|
+
description: 'Critical Percentage threshold for filter',
|
87
|
+
short: '-c PERCENTAGE',
|
88
|
+
long: '--critical PERCENTAGE'
|
89
|
+
|
90
|
+
def run
|
91
|
+
tenant_id = config[:tenant_id]
|
92
|
+
client_id = config[:client_id]
|
93
|
+
client_secret = config[:client_secret]
|
94
|
+
subscription_id = config[:subscription_id]
|
95
|
+
location = config[:location]
|
96
|
+
|
97
|
+
usage_client = NetworkUsage.new.build_usage_client(tenant_id, client_id, client_secret, subscription_id)
|
98
|
+
result = Common.new.retrieve_usage_stats(usage_client, location, 'RouteTables')
|
99
|
+
|
100
|
+
current_usage = result.current_value
|
101
|
+
allowance = result.limit
|
102
|
+
critical_percentage = config[:critical_percentage].to_f
|
103
|
+
warning_percentage = config[:warning_percentage].to_f
|
104
|
+
|
105
|
+
message = "Current usage: #{current_usage} of #{allowance} Route Tables"
|
106
|
+
|
107
|
+
percentage_used = (current_usage.to_f / allowance.to_f) * 100
|
108
|
+
|
109
|
+
if percentage_used >= critical_percentage
|
110
|
+
critical message
|
111
|
+
elsif percentage_used >= warning_percentage
|
112
|
+
warning message
|
113
|
+
else
|
114
|
+
ok message
|
115
|
+
end
|
116
|
+
|
117
|
+
rescue => e
|
118
|
+
puts "Error: exception: #{e}"
|
119
|
+
critical
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# check-azurerm-static-public-ip-addresses-usage
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# This plugin checks the number of Static Public IP Addresses allocated and available in a Region in Azure.
|
7
|
+
# Warning and Critical Percentage thresholds may be set as needed.
|
8
|
+
#
|
9
|
+
# OUTPUT:
|
10
|
+
# plain-text
|
11
|
+
#
|
12
|
+
# PLATFORMS:
|
13
|
+
# Linux
|
14
|
+
#
|
15
|
+
# DEPENDENCIES:
|
16
|
+
# gem: azure_mgmt_network
|
17
|
+
# gem: sensu-plugin
|
18
|
+
#
|
19
|
+
# USAGE:
|
20
|
+
# ./check-azurerm-static-public-ip-addresses-usage.rb -l "westeurope" -w 80 -c 90
|
21
|
+
#
|
22
|
+
# ./check-azurerm-static-public-ip-addresses-usage.rb -t "00000000-0000-0000-0000-000000000000"
|
23
|
+
# -c "00000000-0000-0000-0000-000000000000"
|
24
|
+
# -S "00000000-0000-0000-0000-000000000000"
|
25
|
+
# -s "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234"
|
26
|
+
# -l "eastus2" -w 80 -c 90
|
27
|
+
#
|
28
|
+
# ./check-azurerm-static-public-ip-addresses-usage.rb -tenant "00000000-0000-0000-0000-000000000000"
|
29
|
+
# -client_id "00000000-0000-0000-0000-000000000000"
|
30
|
+
# -client_secret "00000000-0000-0000-0000-000000000000"
|
31
|
+
# -subscription "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234"
|
32
|
+
# -location "westeurope"
|
33
|
+
# -warning_percentage 80
|
34
|
+
# -critical_percentage 90
|
35
|
+
#
|
36
|
+
# NOTES:
|
37
|
+
#
|
38
|
+
# LICENSE:
|
39
|
+
# Tom Harvey
|
40
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
41
|
+
# for details.
|
42
|
+
#
|
43
|
+
|
44
|
+
require 'azure_mgmt_network'
|
45
|
+
require 'sensu-plugin/check/cli'
|
46
|
+
require 'sensu-plugins-azurerm'
|
47
|
+
|
48
|
+
class CheckAzureRMStaticPublicIPAddressesUsage < Sensu::Plugin::Check::CLI
|
49
|
+
include SensuPluginsAzureRM
|
50
|
+
|
51
|
+
option :tenant_id,
|
52
|
+
description: 'ARM Tenant ID. Either set ENV[\'ARM_TENANT_ID\'] or provide it as an option',
|
53
|
+
short: '-t ID',
|
54
|
+
long: '--tenant ID',
|
55
|
+
default: ENV['ARM_TENANT_ID'] # TODO: can we pull these out from the Check too?
|
56
|
+
|
57
|
+
option :client_id,
|
58
|
+
description: 'ARM Client ID. Either set ENV[\'ARM_CLIENT_ID\'] or provide it as an option',
|
59
|
+
short: '-c ID',
|
60
|
+
long: '--client ID',
|
61
|
+
default: ENV['ARM_CLIENT_ID']
|
62
|
+
|
63
|
+
option :client_secret,
|
64
|
+
description: 'ARM Client Secret. Either set ENV[\'ARM_CLIENT_SECRET\'] or provide it as an option',
|
65
|
+
short: '-s SECRET',
|
66
|
+
long: '--clientSecret SECRET',
|
67
|
+
default: ENV['ARM_CLIENT_SECRET']
|
68
|
+
|
69
|
+
option :subscription_id,
|
70
|
+
description: 'ARM Subscription ID',
|
71
|
+
short: '-S ID',
|
72
|
+
long: '--subscription ID',
|
73
|
+
default: ENV['ARM_SUBSCRIPTION_ID']
|
74
|
+
|
75
|
+
option :location,
|
76
|
+
description: 'Azure Location (e.g. westeurope/eastus2)',
|
77
|
+
short: '-l LOCATION',
|
78
|
+
long: '--location LOCATION'
|
79
|
+
|
80
|
+
option :warning_percentage,
|
81
|
+
description: 'Warning Percentage threshold for filter',
|
82
|
+
short: '-w PERCENTAGE',
|
83
|
+
long: '--warning PERCENTAGE'
|
84
|
+
|
85
|
+
option :critical_percentage,
|
86
|
+
description: 'Critical Percentage threshold for filter',
|
87
|
+
short: '-c PERCENTAGE',
|
88
|
+
long: '--critical PERCENTAGE'
|
89
|
+
|
90
|
+
def run
|
91
|
+
tenant_id = config[:tenant_id]
|
92
|
+
client_id = config[:client_id]
|
93
|
+
client_secret = config[:client_secret]
|
94
|
+
subscription_id = config[:subscription_id]
|
95
|
+
location = config[:location]
|
96
|
+
|
97
|
+
usage_client = NetworkUsage.new.build_usage_client(tenant_id, client_id, client_secret, subscription_id)
|
98
|
+
result = Common.new.retrieve_usage_stats(usage_client, location, 'StaticPublicIPAddresses')
|
99
|
+
|
100
|
+
current_usage = result.current_value
|
101
|
+
allowance = result.limit
|
102
|
+
critical_percentage = config[:critical_percentage].to_f
|
103
|
+
warning_percentage = config[:warning_percentage].to_f
|
104
|
+
|
105
|
+
message = "Current usage: #{current_usage} of #{allowance} Static IP Addresses"
|
106
|
+
|
107
|
+
percentage_used = (current_usage.to_f / allowance.to_f) * 100
|
108
|
+
|
109
|
+
if percentage_used >= critical_percentage
|
110
|
+
critical message
|
111
|
+
elsif percentage_used >= warning_percentage
|
112
|
+
warning message
|
113
|
+
else
|
114
|
+
ok message
|
115
|
+
end
|
116
|
+
|
117
|
+
rescue => e
|
118
|
+
puts "Error: exception: #{e}"
|
119
|
+
critical
|
120
|
+
end
|
121
|
+
end
|