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
@@ -28,7 +28,7 @@
|
|
28
28
|
# ./check-azurerm-virtual-machines-usage.rb -tenant "00000000-0000-0000-0000-000000000000"
|
29
29
|
# -client_id "00000000-0000-0000-0000-000000000000"
|
30
30
|
# -client_secret "00000000-0000-0000-0000-000000000000"
|
31
|
-
# -
|
31
|
+
# -subscription "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234"
|
32
32
|
# -location "westeurope"
|
33
33
|
# -warning_percentage 80
|
34
34
|
# -critical_percentage 90
|
@@ -41,76 +41,74 @@
|
|
41
41
|
# for details.
|
42
42
|
#
|
43
43
|
|
44
|
+
require 'azure_mgmt_compute'
|
44
45
|
require 'sensu-plugin/check/cli'
|
45
46
|
require 'sensu-plugins-azurerm'
|
46
|
-
require 'azure_mgmt_compute'
|
47
47
|
|
48
48
|
class CheckAzureRMVMUsage < Sensu::Plugin::Check::CLI
|
49
49
|
include SensuPluginsAzureRM
|
50
50
|
|
51
51
|
option :tenant_id,
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
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
56
|
|
57
57
|
option :client_id,
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
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
62
|
|
63
63
|
option :client_secret,
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
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
68
|
|
69
69
|
option :subscription_id,
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
70
|
+
description: 'ARM Subscription ID',
|
71
|
+
short: '-S ID',
|
72
|
+
long: '--subscription ID',
|
73
|
+
default: ENV['ARM_SUBSCRIPTION_ID']
|
74
74
|
|
75
75
|
option :location,
|
76
|
-
|
77
|
-
|
78
|
-
|
76
|
+
description: 'Azure Location (e.g. westeurope/eastus2)',
|
77
|
+
short: '-l LOCATION',
|
78
|
+
long: '--location LOCATION'
|
79
79
|
|
80
80
|
option :warning_percentage,
|
81
|
-
|
82
|
-
|
83
|
-
|
81
|
+
description: 'Warning Percentage threshold for filter',
|
82
|
+
short: '-w PERCENTAGE',
|
83
|
+
long: '--warning PERCENTAGE'
|
84
84
|
|
85
85
|
option :critical_percentage,
|
86
|
-
|
87
|
-
|
88
|
-
|
86
|
+
description: 'Critical Percentage threshold for filter',
|
87
|
+
short: '-c PERCENTAGE',
|
88
|
+
long: '--critical PERCENTAGE'
|
89
89
|
|
90
90
|
def run
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
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
95
|
location = config[:location]
|
96
96
|
|
97
|
-
|
98
|
-
|
99
|
-
usageClient = common.buildUsageOperationClient(tenantId, clientId, clientSecret, subscriptionId)
|
100
|
-
result = common.retrieveUsageStats(usageClient, location, 'virtualMachines')
|
97
|
+
usage_client = ComputeUsage.new.build_usage_operation_client(tenant_id, client_id, client_secret, subscription_id)
|
98
|
+
result = Common.new.retrieve_usage_stats(usage_client, location, 'virtualMachines')
|
101
99
|
|
102
100
|
current_usage = result.current_value
|
103
101
|
allowance = result.limit
|
104
|
-
|
105
|
-
|
102
|
+
critical_percentage = config[:critical_percentage].to_f
|
103
|
+
warning_percentage = config[:warning_percentage].to_f
|
106
104
|
|
107
105
|
message = "Current usage: #{current_usage} of #{allowance} VMs"
|
108
106
|
|
109
107
|
percentage_used = (current_usage.to_f / allowance.to_f) * 100
|
110
108
|
|
111
|
-
if percentage_used >=
|
109
|
+
if percentage_used >= critical_percentage
|
112
110
|
critical message
|
113
|
-
elsif percentage_used >=
|
111
|
+
elsif percentage_used >= warning_percentage
|
114
112
|
warning message
|
115
113
|
else
|
116
114
|
ok message
|
@@ -120,5 +118,4 @@ class CheckAzureRMVMUsage < Sensu::Plugin::Check::CLI
|
|
120
118
|
puts "Error: exception: #{e}"
|
121
119
|
critical
|
122
120
|
end
|
123
|
-
|
124
121
|
end
|
@@ -30,7 +30,7 @@
|
|
30
30
|
# -tenant "00000000-0000-0000-0000-000000000000"
|
31
31
|
# -client "00000000-0000-0000-0000-000000000000"
|
32
32
|
# -clientSecret "00000000-0000-0000-0000-000000000000"
|
33
|
-
# -
|
33
|
+
# -subscription "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234"
|
34
34
|
# -resourceGroup "resourcegroup"
|
35
35
|
# -name "gatewayname"
|
36
36
|
#
|
@@ -42,66 +42,64 @@
|
|
42
42
|
# for details.
|
43
43
|
#
|
44
44
|
|
45
|
+
require 'azure_mgmt_network'
|
45
46
|
require 'sensu-plugin/check/cli'
|
46
47
|
require 'sensu-plugins-azurerm'
|
47
|
-
require 'azure_mgmt_network'
|
48
48
|
|
49
49
|
class CheckAzureRMVirtualNetworkGatewayConnected < Sensu::Plugin::Check::CLI
|
50
50
|
include SensuPluginsAzureRM
|
51
51
|
|
52
52
|
option :tenant_id,
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
53
|
+
description: 'ARM Tenant ID. Either set ENV[\'ARM_TENANT_ID\'] or provide it as an option',
|
54
|
+
short: '-t ID',
|
55
|
+
long: '--tenant ID',
|
56
|
+
default: ENV['ARM_TENANT_ID'] # TODO: can we pull these out from the Check too?
|
57
57
|
|
58
58
|
option :client_id,
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
59
|
+
description: 'ARM Client ID. Either set ENV[\'ARM_CLIENT_ID\'] or provide it as an option',
|
60
|
+
short: '-c ID',
|
61
|
+
long: '--client ID',
|
62
|
+
default: ENV['ARM_CLIENT_ID']
|
63
63
|
|
64
64
|
option :client_secret,
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
65
|
+
description: 'ARM Client Secret. Either set ENV[\'ARM_CLIENT_SECRET\'] or provide it as an option',
|
66
|
+
short: '-s SECRET',
|
67
|
+
long: '--clientSecret SECRET',
|
68
|
+
default: ENV['ARM_CLIENT_SECRET']
|
69
69
|
|
70
70
|
option :subscription_id,
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
71
|
+
description: 'ARM Subscription ID',
|
72
|
+
short: '-S ID',
|
73
|
+
long: '--subscription ID',
|
74
|
+
default: ENV['ARM_SUBSCRIPTION_ID']
|
75
75
|
|
76
76
|
option :resource_group_name,
|
77
|
-
|
78
|
-
|
79
|
-
|
77
|
+
description: 'Azure Resource Group Name',
|
78
|
+
short: '-r RESOURCEGROUP',
|
79
|
+
long: '--resourceGroup RESOURCEGROUP'
|
80
80
|
|
81
81
|
option :name,
|
82
|
-
|
83
|
-
|
84
|
-
|
82
|
+
description: 'Azure Virtual Network Connection Gateway Name',
|
83
|
+
short: '-n NAME',
|
84
|
+
long: '--name NAME'
|
85
85
|
|
86
86
|
def run
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
87
|
+
tenant_id = config[:tenant_id]
|
88
|
+
client_id = config[:client_id]
|
89
|
+
client_secret = config[:client_secret]
|
90
|
+
subscription_id = config[:subscription_id]
|
91
91
|
|
92
92
|
resource_group_name = config[:resource_group_name]
|
93
93
|
name = config[:name]
|
94
94
|
|
95
|
-
|
96
|
-
|
97
|
-
networkClient = usage.buildVirtualNetworkClient(tenantId, clientId, clientSecret, subscriptionId)
|
98
|
-
result = networkClient.get(resource_group_name, name)
|
95
|
+
network_client = NetworkUsage.new.build_virtual_network_gateways_client(tenant_id, client_id, client_secret, subscription_id)
|
96
|
+
result = network_client.get(resource_group_name, name)
|
99
97
|
|
100
98
|
connection_state = result.connection_status
|
101
99
|
inbound = result.ingress_bytes_transferred
|
102
100
|
outbound = result.egress_bytes_transferred
|
103
101
|
message = "State is '#{connection_state}'. Usage is #{inbound} in / #{outbound} out"
|
104
|
-
if result.connection_status.casecmp(
|
102
|
+
if result.connection_status.casecmp('connected') == 0
|
105
103
|
ok message
|
106
104
|
else
|
107
105
|
critical message
|
@@ -111,5 +109,4 @@ class CheckAzureRMVirtualNetworkGatewayConnected < Sensu::Plugin::Check::CLI
|
|
111
109
|
puts "Error: exception: #{e}"
|
112
110
|
critical
|
113
111
|
end
|
114
|
-
|
115
112
|
end
|
@@ -19,8 +19,8 @@
|
|
19
19
|
# USAGE:
|
20
20
|
# ./check-azurerm-virtual-network-gateway-failover-connected.rb
|
21
21
|
# -r "resourcegroup"
|
22
|
-
# -p "
|
23
|
-
# -s "
|
22
|
+
# -p "primary_name"
|
23
|
+
# -s "secondary_name"
|
24
24
|
#
|
25
25
|
# ./check-azurerm-virtual-network-gateway-failover-connected.rb
|
26
26
|
# -t "00000000-0000-0000-0000-000000000000"
|
@@ -28,17 +28,17 @@
|
|
28
28
|
# -S "00000000-0000-0000-0000-000000000000"
|
29
29
|
# -s "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234"
|
30
30
|
# -r "resourcegroup"
|
31
|
-
# -p "
|
32
|
-
# -s "
|
31
|
+
# -p "primary_name"
|
32
|
+
# -s "secondary_name"
|
33
33
|
#
|
34
34
|
# ./check-azurerm-virtual-network-gateway-failover-connected.rb
|
35
35
|
# -tenant "00000000-0000-0000-0000-000000000000"
|
36
36
|
# -client "00000000-0000-0000-0000-000000000000"
|
37
|
-
# -
|
38
|
-
# -
|
37
|
+
# -client_secret "00000000-0000-0000-0000-000000000000"
|
38
|
+
# -subscription "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234"
|
39
39
|
# -resourceGroup "resourcegroup"
|
40
|
-
# -
|
41
|
-
# -
|
40
|
+
# -primary_name "gatewayname"
|
41
|
+
# -secondary_name "gatewayname"
|
42
42
|
#
|
43
43
|
# NOTES:
|
44
44
|
#
|
@@ -48,81 +48,79 @@
|
|
48
48
|
# for details.
|
49
49
|
#
|
50
50
|
|
51
|
+
require 'azure_mgmt_network'
|
51
52
|
require 'sensu-plugin/check/cli'
|
52
53
|
require 'sensu-plugins-azurerm'
|
53
|
-
require 'azure_mgmt_network'
|
54
54
|
|
55
55
|
class CheckAzureRMVirtualNetworkGatewayConnected < Sensu::Plugin::Check::CLI
|
56
56
|
include SensuPluginsAzureRM
|
57
57
|
|
58
58
|
option :tenant_id,
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
59
|
+
description: 'ARM Tenant ID. Either set ENV[\'ARM_TENANT_ID\'] or provide it as an option',
|
60
|
+
short: '-t ID',
|
61
|
+
long: '--tenant ID',
|
62
|
+
default: ENV['ARM_TENANT_ID'] # TODO: can we pull these out from the Check too?
|
63
63
|
|
64
64
|
option :client_id,
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
65
|
+
description: 'ARM Client ID. Either set ENV[\'ARM_CLIENT_ID\'] or provide it as an option',
|
66
|
+
short: '-c ID',
|
67
|
+
long: '--client ID',
|
68
|
+
default: ENV['ARM_CLIENT_ID']
|
69
69
|
|
70
70
|
option :client_secret,
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
71
|
+
description: 'ARM Client Secret. Either set ENV[\'ARM_CLIENT_SECRET\'] or provide it as an option',
|
72
|
+
short: '-s SECRET',
|
73
|
+
long: '--client_secret SECRET',
|
74
|
+
default: ENV['ARM_CLIENT_SECRET']
|
75
75
|
|
76
76
|
option :subscription_id,
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
77
|
+
description: 'ARM Subscription ID',
|
78
|
+
short: '-S ID',
|
79
|
+
long: '--subscription ID',
|
80
|
+
default: ENV['ARM_SUBSCRIPTION_ID']
|
81
81
|
|
82
82
|
option :resource_group_name,
|
83
|
-
|
84
|
-
|
85
|
-
|
83
|
+
description: 'Azure Resource Group Name',
|
84
|
+
short: '-r RESOURCEGROUP',
|
85
|
+
long: '--resourceGroup RESOURCEGROUP'
|
86
86
|
|
87
87
|
option :primary_name,
|
88
|
-
|
89
|
-
|
90
|
-
|
88
|
+
description: 'Azure Virtual Network Connection Gateway Primary Name',
|
89
|
+
short: '-p NAME',
|
90
|
+
long: '--primary_name NAME'
|
91
91
|
|
92
92
|
option :secondary_name,
|
93
|
-
|
94
|
-
|
95
|
-
|
93
|
+
description: 'Azure Virtual Network Connection Gateway Secondary Name',
|
94
|
+
short: '-s NAME',
|
95
|
+
long: '--secondary_name NAME'
|
96
96
|
|
97
97
|
def run
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
98
|
+
tenant_id = config[:tenant_id]
|
99
|
+
client_id = config[:client_id]
|
100
|
+
client_secret = config[:client_secret]
|
101
|
+
subscription_id = config[:subscription_id]
|
102
102
|
|
103
103
|
resource_group_name = config[:resource_group_name]
|
104
104
|
|
105
|
-
|
106
|
-
|
105
|
+
primary_name = config[:primary_name]
|
106
|
+
secondary_name = config[:secondary_name]
|
107
107
|
|
108
|
-
|
108
|
+
network_client = NetworkUsage.new.build_virtual_network_gateways_client(tenant_id, client_id, client_secret, subscription_id)
|
109
109
|
|
110
|
-
|
110
|
+
primary_result = network_client.get(resource_group_name, primary_name)
|
111
|
+
primary_connection_state = primary_result.connection_status
|
112
|
+
primary_inbound = primary_result.ingress_bytes_transferred
|
113
|
+
primary_outbound = primary_result.egress_bytes_transferred
|
111
114
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
secondaryResult = networkClient.get(resource_group_name, secondaryName)
|
118
|
-
secondary_connection_state = secondaryResult.connection_status
|
119
|
-
secondary_inbound = secondaryResult.ingress_bytes_transferred
|
120
|
-
secondary_outbound = secondaryResult.egress_bytes_transferred
|
115
|
+
secondary_result = network_client.get(resource_group_name, secondary_name)
|
116
|
+
secondary_connection_state = secondary_result.connection_status
|
117
|
+
secondary_inbound = secondary_result.ingress_bytes_transferred
|
118
|
+
secondary_outbound = secondary_result.egress_bytes_transferred
|
121
119
|
message = "Primary: State is '#{primary_connection_state}'. Usage is #{primary_inbound} in / #{primary_outbound} out.\n"
|
122
120
|
message += "Secondary: State is '#{secondary_connection_state}'. Usage is #{secondary_inbound} in / #{secondary_outbound} out."
|
123
121
|
|
124
|
-
if
|
125
|
-
|
122
|
+
if primary_result.connection_status.casecmp('connected') == 0 ||
|
123
|
+
secondary_result.connection_status.casecmp('connected') == 0
|
126
124
|
ok message
|
127
125
|
else
|
128
126
|
critical message
|
@@ -132,5 +130,4 @@ class CheckAzureRMVirtualNetworkGatewayConnected < Sensu::Plugin::Check::CLI
|
|
132
130
|
puts "Error: exception: #{e}"
|
133
131
|
critical
|
134
132
|
end
|
135
|
-
|
136
133
|
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# check-azurerm-virtual-networks-usage
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# This plugin checks the number of Virtual Networks 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-virtual-networks-usage.rb -l "westeurope" -w 80 -c 90
|
21
|
+
#
|
22
|
+
# ./check-azurerm-virtual-networks-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-virtual-networks-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 CheckAzureRMVirtualNetworksUsage < 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, 'VirtualNetworks')
|
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} Virtual Networks"
|
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
|