Skip to content

Commit 6f89f19

Browse files
authored
Merge pull request #207 from Icinga:feature/customize_check_label
Adds feature to customize label for checks Adds new Argument `-LabelName` to `New-IcingaCheck`, allowing the developer to provide custom label names for checks and override the default based on the check name.
2 parents ec65665 + b6da72b commit 6f89f19

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

doc/31-Changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
1818
* [#198](https://github.com/Icinga/icinga-powershell-framework/pull/198) Adds support to flush the content of the Icinga Agent API directory with a single Cmdlet `Clear-IcingaAgentApiDirectory`
1919
* [#203](https://github.com/Icinga/icinga-powershell-framework/pull/203) Removes experimental state of the Icinga PowerShell Framework code caching and adds docs on how to use the feature
2020
* [#205](https://github.com/Icinga/icinga-powershell-framework/pull/205) Ensure Icinga for Windows configuration file is opened as read-only for every single task besides actually modifying configuration content
21+
* [#207](https://github.com/Icinga/icinga-powershell-framework/pull/207) Adds new Argument `-LabelName` to `New-IcingaCheck`, allowing the developer to provide custom label names for checks and override the default based on the check name.
2122

2223
### Bugfixes
2324

doc/developerguide/01-New-IcingaCheck.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@ For performance metrics you can provide a `Unit` to ensure your graphing is disp
3131
| Maximum | String | | The maximum value which is displayed on your graphs |
3232
| ObjectExists | Bool | | If you are using values coming from objects, like Services, you can use this argument to determin if the object itself exist or not. In case it doesn't, you will receive a proper output on the check result |
3333
| Translation | Hashtable | | In case you want to map values to certain descriptions, you can place a hashtable at this argument which will then map the value to the description on the check result. For example this would apply to service running states |
34+
| LabelName | String | | Allows to override the default label name generated based on the `-Name` argument to a custom name. Please ensure to remove any special characters manually, as the name set here is the exact name for the label |
3435
| NoPerfData | Switch | | Disables Performance Data output for this check object |
3536

3637
## Units
3738

3839
| Unit | Name | Description |
3940
| --- | --- | --- |
40-
| % | Percentage | The input value is a percentual value |
41+
| % | Percentage | The input value is a percentage value |
4142
| s | Seconds | The input is indicated as time seconds |
4243
| ms | Milliseconds | The input is indicated as time in milliseconds |
4344
| us | Microseconds | The input is indicated as time in microseconds |

lib/icinga/plugin/New-IcingaCheck.psm1

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ function New-IcingaCheck()
1111
[string]$Maximum = '',
1212
$ObjectExists = -1,
1313
$Translation = $null,
14+
[string]$LabelName = $null,
1415
[switch]$NoPerfData
1516
);
1617

@@ -38,6 +39,7 @@ function New-IcingaCheck()
3839
$Check | Add-Member -MemberType NoteProperty -Name 'maximum' -Value $Maximum;
3940
$Check | Add-Member -MemberType NoteProperty -Name 'objectexists' -Value $ObjectExists;
4041
$Check | Add-Member -MemberType NoteProperty -Name 'translation' -Value $Translation;
42+
$Check | Add-Member -MemberType NoteProperty -Name 'labelname' -Value $LabelName;
4143
$Check | Add-Member -MemberType NoteProperty -Name 'checks' -Value $null;
4244
$Check | Add-Member -MemberType NoteProperty -Name 'completed' -Value $FALSE;
4345
$Check | Add-Member -MemberType NoteProperty -Name 'checkcommand' -Value '';
@@ -803,6 +805,10 @@ function New-IcingaCheck()
803805
$warning = ConvertTo-Integer -Value $this.warning -NullAsEmpty;
804806
$critical = ConvertTo-Integer -Value $this.critical -NullAsEmpty;
805807

808+
if ([string]::IsNullOrEmpty($this.labelname) -eq $FALSE) {
809+
$LabelName = $this.labelname;
810+
}
811+
806812
$perfdata = @{
807813
'label' = $LabelName;
808814
'perfdata' = '';

0 commit comments

Comments
 (0)