Skip to content

Commit

Permalink
Merge pull request #233 from Icinga:fix/improve_partition_space_plugi…
Browse files Browse the repository at this point in the history
…n_performance

Fix: Rework partition space plugin

Reworks the partition space plugin to increase performance by only fetching partition information instead of entire disk data and also adds support to toggle between free and used space monitoring.
  • Loading branch information
LordHepipud authored Nov 8, 2021
2 parents 2f2dec4 + f2e008d commit cb8d93d
Show file tree
Hide file tree
Showing 18 changed files with 614 additions and 370 deletions.
1 change: 1 addition & 0 deletions config/director/Invoke-IcingaCheckPartitionSpace.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"DataList":{"IcingaCheckPartitionSpace Verbosity":{"list_name":"IcingaCheckPartitionSpace Verbosity","originalId":"2","entries":[{"allowed_roles":null,"entry_value":"0","entry_name":"0","format":"string"},{"allowed_roles":null,"entry_value":"1","entry_name":"1","format":"string"},{"allowed_roles":null,"entry_value":"2","entry_name":"2","format":"string"},{"allowed_roles":null,"entry_value":"3","entry_name":"3","format":"string"}],"owner":"stein"},"PowerShell ExecutionPolicies":{"list_name":"PowerShell ExecutionPolicies","originalId":"2","entries":[{"allowed_roles":null,"entry_value":"AllSigned","entry_name":"AllSigned","format":"string"},{"allowed_roles":null,"entry_value":"Bypass","entry_name":"Bypass","format":"string"},{"allowed_roles":null,"entry_value":"Default","entry_name":"Default","format":"string"},{"allowed_roles":null,"entry_value":"RemoteSigned","entry_name":"RemoteSigned","format":"string"},{"allowed_roles":null,"entry_value":"Restricted","entry_name":"Restricted","format":"string"},{"allowed_roles":null,"entry_value":"Undefined","entry_name":"Undefined","format":"string"},{"allowed_roles":null,"entry_value":"Unrestricted","entry_name":"Unrestricted","format":"string"}],"owner":"stein"}},"Command":{"PowerShell Base":{"methods_execute":"PluginCheck","object_name":"PowerShell Base","vars":{"IcingaPowerShellBase_String_ExecutionPolicy":"ByPass"},"is_string":null,"command":"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe","zone":null,"disabled":false,"fields":[{"datafield_id":2,"is_required":"n","var_filter":null}],"arguments":{"-ExecutionPolicy":{"value":"$IcingaPowerShellBase_String_ExecutionPolicy$","order":"-1"},"-NoProfile":{"set_if":true,"order":"-3"},"-NoLogo":{"set_if":true,"order":"-2"}},"imports":[],"object_type":"object","timeout":"180"},"Invoke-IcingaCheckPartitionSpace":{"fields":[{"datafield_id":4,"is_required":"n","var_filter":null},{"datafield_id":5,"is_required":"n","var_filter":null},{"datafield_id":6,"is_required":"n","var_filter":null},{"datafield_id":7,"is_required":"n","var_filter":null},{"datafield_id":8,"is_required":"n","var_filter":null},{"datafield_id":9,"is_required":"n","var_filter":null},{"datafield_id":10,"is_required":"n","var_filter":null},{"datafield_id":11,"is_required":"n","var_filter":null},{"datafield_id":12,"is_required":"n","var_filter":null},{"datafield_id":13,"is_required":"n","var_filter":null}],"object_name":"Invoke-IcingaCheckPartitionSpace","arguments":{"-C":{"value":"try { Use-Icinga -Minimal; } catch { Write-Output \u0027The Icinga PowerShell Framework is either not installed on the system or not configured properly. Please check https://icinga.com/docs/windows for further details\u0027; Write-Output \u0027Error:\u0027 $$($$_.Exception.Message)Components:`r`n$$( Get-Module -ListAvailable \u0027icinga-powershell-*\u0027 )`r`n\u0027Module-Path:\u0027`r`n$$($$Env:PSModulePath); exit 3; }; Exit-IcingaExecutePlugin -Command \u0027Invoke-IcingaCheckPartitionSpace\u0027 ","order":"0"},"-Verbosity":{"value":"$IcingaCheckPartitionSpace_Int32_Verbosity$","order":"6"},"-ThresholdInterval":{"value":"$IcingaCheckPartitionSpace_String_ThresholdInterval$","order":"100"},"-IgnoreEmptyChecks":{"set_if":"$IcingaCheckPartitionSpace_Switchparameter_IgnoreEmptyChecks$","set_if_format":"string","order":"99"},"-Include":{"value":{"body":"var arr = macro(\"$IcingaCheckPartitionSpace_Array_Include$\");\r\n if (len(arr) == 0) {\r\n return \"@()\";\r\n }\r\n return arr.map(\r\n x =\u003e if (typeof(x) == String) {\r\n var argLen = len(x);\r\n if (argLen != 0 \u0026\u0026 x.substr(0,1) == \"\u0027\" \u0026\u0026 x.substr(argLen - 1, argLen) == \"\u0027\") {\r\n x;\r\n } else {\r\n \"\u0027\" + x + \"\u0027\";\r\n }\r\n } else {\r\n x;\r\n }\r\n ).join(\",\");","type":"Function"},"order":"4"},"-Warning":{"value":"$IcingaCheckPartitionSpace_Object_Warning$","order":"2"},"-Critical":{"value":"$IcingaCheckPartitionSpace_Object_Critical$","order":"3"},"-NoPerfData":{"set_if":"$IcingaCheckPartitionSpace_Switchparameter_NoPerfData$","set_if_format":"string","order":"99"},"-CheckUsedSpace":{"set_if":"$IcingaCheckPartitionSpace_Switchparameter_CheckUsedSpace$","set_if_format":"string","order":"99"},"-Exclude":{"value":{"body":"var arr = macro(\"$IcingaCheckPartitionSpace_Array_Exclude$\");\r\n if (len(arr) == 0) {\r\n return \"@()\";\r\n }\r\n return arr.map(\r\n x =\u003e if (typeof(x) == String) {\r\n var argLen = len(x);\r\n if (argLen != 0 \u0026\u0026 x.substr(0,1) == \"\u0027\" \u0026\u0026 x.substr(argLen - 1, argLen) == \"\u0027\") {\r\n x;\r\n } else {\r\n \"\u0027\" + x + \"\u0027\";\r\n }\r\n } else {\r\n x;\r\n }\r\n ).join(\",\");","type":"Function"},"order":"5"},"-SkipUnknown":{"set_if":"$IcingaCheckPartitionSpace_Switchparameter_SkipUnknown$","set_if_format":"string","order":"99"}},"imports":["PowerShell Base"],"object_type":"object","vars":{"IcingaCheckPartitionSpace_Switchparameter_SkipUnknown":false,"IcingaCheckPartitionSpace_Switchparameter_IgnoreEmptyChecks":false,"IcingaCheckPartitionSpace_Switchparameter_NoPerfData":false,"IcingaCheckPartitionSpace_Switchparameter_CheckUsedSpace":false}}},"Datafield":{"7":{"settings":{"visibility":"visible"},"description":"Used to specify an array of partitions to be included. If not set, the check expects that all not excluded partitions should be checked.\ne.g. \u0027C:\u0027,\u0027D:\u0027","caption":"Include","datatype":"Icinga\\Module\\Director\\DataType\\DataTypeArray","originalId":"7","varname":"IcingaCheckPartitionSpace_Array_Include","format":null},"9":{"settings":{"visibility":"visible"},"description":"Overrides the default behaviour of the plugin in case no check element is left for being checked (if all elements are filtered out for example).\nInstead of returning `Unknown` the plugin will return `Ok` instead if this argument is set.","caption":"IgnoreEmptyChecks","datatype":"Icinga\\Module\\Director\\DataType\\DataTypeBoolean","originalId":"9","varname":"IcingaCheckPartitionSpace_Switchparameter_IgnoreEmptyChecks","format":null},"10":{"settings":{"visibility":"visible"},"description":"Disables the performance data output of this plugin","caption":"NoPerfData","datatype":"Icinga\\Module\\Director\\DataType\\DataTypeBoolean","originalId":"10","varname":"IcingaCheckPartitionSpace_Switchparameter_NoPerfData","format":null},"12":{"settings":{"visibility":"visible"},"description":"Switches the behaviour of the plugin from checking with threshold for the free space (default) to the remaining (used) space instead","caption":"CheckUsedSpace","datatype":"Icinga\\Module\\Director\\DataType\\DataTypeBoolean","originalId":"12","varname":"IcingaCheckPartitionSpace_Switchparameter_CheckUsedSpace","format":null},"11":{"settings":{"visibility":"visible"},"description":"Allows to set Unknown partitions to Ok in case no metrics could be loaded.","caption":"SkipUnknown","datatype":"Icinga\\Module\\Director\\DataType\\DataTypeBoolean","originalId":"11","varname":"IcingaCheckPartitionSpace_Switchparameter_SkipUnknown","format":null},"2":{"settings":{"datalist":"PowerShell ExecutionPolicies","behavior":"strict","data_type":"string"},"description":"Defines with which Execution Policy the PowerShell is started","caption":"PowerShell Execution Policy","datatype":"Icinga\\Module\\Director\\DataType\\DataTypeDatalist","originalId":"2","varname":"IcingaPowerShellBase_String_ExecutionPolicy","format":null},"4":{"settings":{"visibility":"visible"},"description":"Change the value your defined threshold checks against from the current value to a collected time threshold of the Icinga for Windows daemon, as described here: https://icinga.com/docs/icinga-for-windows/latest/doc/service/10-Register-Service-Checks/ An example for this argument would be 1m or 15m which will use the average of 1m or 15m for monitoring.","caption":"ThresholdInterval","datatype":"Icinga\\Module\\Director\\DataType\\DataTypeString","originalId":"4","varname":"IcingaCheckPartitionSpace_String_ThresholdInterval","format":null},"13":{"settings":{"datalist":"IcingaCheckPartitionSpace Verbosity","behavior":"strict","data_type":"string"},"description":"Changes the behavior of the plugin output which check states are printed:\n0 (default): Only service checks/packages with state not OK will be printed\n1: Only services with not OK will be printed including OK checks of affected check packages including Package config\n2: Everything will be printed regardless of the check state\n3: Identical to Verbose 2, but prints in addition the check package configuration e.g (All must be [OK])","caption":"Verbosity","datatype":"Icinga\\Module\\Director\\DataType\\DataTypeDatalist","originalId":"13","varname":"IcingaCheckPartitionSpace_Int32_Verbosity","format":null},"6":{"settings":{"visibility":"visible"},"description":"Used to specify a Critical threshold. This can either be a byte-value type like \u002710GB\u0027\nor a %-value, like \u002710%\u0027","caption":"Critical","datatype":"Icinga\\Module\\Director\\DataType\\DataTypeString","originalId":"6","varname":"IcingaCheckPartitionSpace_Object_Critical","format":null},"5":{"settings":{"visibility":"visible"},"description":"Used to specify a Warning threshold. This can either be a byte-value type like \u002710GB\u0027\nor a %-value, like \u002710%\u0027","caption":"Warning","datatype":"Icinga\\Module\\Director\\DataType\\DataTypeString","originalId":"5","varname":"IcingaCheckPartitionSpace_Object_Warning","format":null},"8":{"settings":{"visibility":"visible"},"description":"Used to specify an array of partitions to be excluded.\ne.g. \u0027C:\u0027,\u0027D:\u0027","caption":"Exclude","datatype":"Icinga\\Module\\Director\\DataType\\DataTypeArray","originalId":"8","varname":"IcingaCheckPartitionSpace_Array_Exclude","format":null}}}
2 changes: 1 addition & 1 deletion config/director/Invoke-IcingaCheckUsedPartitionSpace.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion config/director/Plugins_Bundle.json

Large diffs are not rendered by default.

94 changes: 94 additions & 0 deletions config/icinga/Invoke-IcingaCheckPartitionSpace.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
object CheckCommand "Invoke-IcingaCheckPartitionSpace" {
import "PowerShell Base"

arguments += {
"-C" = {
value = "try { Use-Icinga -Minimal; } catch { Write-Output 'The Icinga PowerShell Framework is either not installed on the system or not configured properly. Please check https://icinga.com/docs/windows for further details'; Write-Output 'Error:' $$($$_.Exception.Message)Components:`r`n$$( Get-Module -ListAvailable 'icinga-powershell-*' )`r`n'Module-Path:'`r`n$$($$Env:PSModulePath); exit 3; }; Exit-IcingaExecutePlugin -Command 'Invoke-IcingaCheckPartitionSpace' "
order = 0
}
"-Verbosity" = {
description = "Changes the behavior of the plugin output which check states are printed: 0 (default): Only service checks/packages with state not OK will be printed 1: Only services with not OK will be printed including OK checks of affected check packages including Package config 2: Everything will be printed regardless of the check state 3: Identical to Verbose 2, but prints in addition the check package configuration e.g (All must be [OK])"
value = "$IcingaCheckPartitionSpace_Int32_Verbosity$"
order = 6
}
"-ThresholdInterval" = {
description = "Change the value your defined threshold checks against from the current value to a collected time threshold of the Icinga for Windows daemon, as described here: https://icinga.com/docs/icinga-for-windows/latest/doc/service/10-Register-Service-Checks/ An example for this argument would be 1m or 15m which will use the average of 1m or 15m for monitoring."
value = "$IcingaCheckPartitionSpace_String_ThresholdInterval$"
order = 100
}
"-IgnoreEmptyChecks" = {
set_if = "$IcingaCheckPartitionSpace_Switchparameter_IgnoreEmptyChecks$"
order = 99
}
"-Include" = {
description = "Used to specify an array of partitions to be included. If not set, the check expects that all not excluded partitions should be checked. e.g. 'C:','D:'"
value = {{
var arr = macro("$IcingaCheckPartitionSpace_Array_Include$");
if (len(arr) == 0) {
return "@()";
}
return arr.map(
x => if (typeof(x) == String) {
var argLen = len(x);
if (argLen != 0 && x.substr(0,1) == "'" && x.substr(argLen - 1, argLen) == "'") {
x;
} else {
"'" + x + "'";
}
} else {
x;
}
).join(",");
}}
order = 4
}
"-Warning" = {
description = "Used to specify a Warning threshold. This can either be a byte-value type like '10GB' or a %-value, like '10%'"
value = "$IcingaCheckPartitionSpace_Object_Warning$"
order = 2
}
"-Critical" = {
description = "Used to specify a Critical threshold. This can either be a byte-value type like '10GB' or a %-value, like '10%'"
value = "$IcingaCheckPartitionSpace_Object_Critical$"
order = 3
}
"-NoPerfData" = {
set_if = "$IcingaCheckPartitionSpace_Switchparameter_NoPerfData$"
order = 99
}
"-CheckUsedSpace" = {
set_if = "$IcingaCheckPartitionSpace_Switchparameter_CheckUsedSpace$"
order = 99
}
"-Exclude" = {
description = "Used to specify an array of partitions to be excluded. e.g. 'C:','D:'"
value = {{
var arr = macro("$IcingaCheckPartitionSpace_Array_Exclude$");
if (len(arr) == 0) {
return "@()";
}
return arr.map(
x => if (typeof(x) == String) {
var argLen = len(x);
if (argLen != 0 && x.substr(0,1) == "'" && x.substr(argLen - 1, argLen) == "'") {
x;
} else {
"'" + x + "'";
}
} else {
x;
}
).join(",");
}}
order = 5
}
"-SkipUnknown" = {
set_if = "$IcingaCheckPartitionSpace_Switchparameter_SkipUnknown$"
order = 99
}
}
vars.IcingaCheckPartitionSpace_Switchparameter_SkipUnknown = false
vars.IcingaCheckPartitionSpace_Switchparameter_IgnoreEmptyChecks = false
vars.IcingaCheckPartitionSpace_Switchparameter_NoPerfData = false
vars.IcingaCheckPartitionSpace_Switchparameter_CheckUsedSpace = false
}
5 changes: 5 additions & 0 deletions config/icinga/Invoke-IcingaCheckUsedPartitionSpace.conf
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ object CheckCommand "Invoke-IcingaCheckUsedPartitionSpace" {
set_if = "$IcingaCheckUsedPartitionSpace_Switchparameter_NoPerfData$"
order = 99
}
"-CheckUsedSpace" = {
set_if = "$IcingaCheckUsedPartitionSpace_Switchparameter_CheckUsedSpace$"
order = 99
}
"-Exclude" = {
description = "Used to specify an array of partitions to be excluded. e.g. 'C:','D:'"
value = {{
Expand Down Expand Up @@ -86,4 +90,5 @@ object CheckCommand "Invoke-IcingaCheckUsedPartitionSpace" {
vars.IcingaCheckUsedPartitionSpace_Switchparameter_SkipUnknown = false
vars.IcingaCheckUsedPartitionSpace_Switchparameter_IgnoreEmptyChecks = false
vars.IcingaCheckUsedPartitionSpace_Switchparameter_NoPerfData = false
vars.IcingaCheckUsedPartitionSpace_Switchparameter_CheckUsedSpace = false
}
Loading

0 comments on commit cb8d93d

Please sign in to comment.