mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-18 15:46:14 -05:00
Fixes lots of code styling, spelling and script analyzer
Disabling UseConsistentIndentation because it is not properly working for multi-line commands with arguments and array/hashtable objects
This commit is contained in:
parent
ac7aad5e07
commit
4ef55bddb4
61 changed files with 209 additions and 202 deletions
|
|
@ -15,7 +15,6 @@
|
|||
'PSUseDeclaredVarsMoreThanAssigments',
|
||||
'PSAvoidTrailingWhitespace',
|
||||
'PSAvoidUsingDeprecatedManifestFields',
|
||||
'PSUseToExportFieldsInManifest',
|
||||
'PSUseProcessBlockForPipelineCommand',
|
||||
'PSUseConsistentIndentation',
|
||||
'PSUseCompatibleCmdlets',
|
||||
|
|
@ -26,7 +25,8 @@
|
|||
ExcludeRules = @(
|
||||
'PSAvoidGlobalVars',
|
||||
'PSUseSingularNouns',
|
||||
'PSAvoidUsingWriteHost'
|
||||
'PSAvoidUsingWriteHost',
|
||||
'PSUseToExportFieldsInManifest'
|
||||
)
|
||||
Rules = @{
|
||||
PSUseCompatibleCmdlets = @{
|
||||
|
|
@ -44,11 +44,13 @@
|
|||
IgnoreOneLineBlock = $true
|
||||
NoEmptyLineBefore = $true
|
||||
};
|
||||
# Disabled for the moment, as the indentation handling is not properly
|
||||
# handling multi-line arrays and hashtables
|
||||
PSUseConsistentIndentation = @{
|
||||
Enable = $true
|
||||
Enable = $false
|
||||
Kind = 'space'
|
||||
IndentationSize = 4
|
||||
PipelineIndentation = 'IncreaseIndentationForFirstPipeline'
|
||||
PipelineIndentation = 'IncreaseIndentationAfterEveryPipeline'
|
||||
};
|
||||
PSUseConsistentWhitespace = @{
|
||||
Enable = $true
|
||||
|
|
|
|||
|
|
@ -172,7 +172,7 @@ You can read more on this on the [Knowledge Base Entry](https://icinga.com/docs/
|
|||
* [#237](https://github.com/Icinga/icinga-powershell-framework/issues/237) Fixes `Icinga PowerShell Framework` root folder lookup, in case the module was installed with PowerShell gallery, which creates version folders for each installed version
|
||||
* [#240](https://github.com/Icinga/icinga-powershell-framework/pull/240) While filtering for certain services with `Get-IcingaServices`, there were some attributes missing from the collection. These are now added resulting in always correct output data.
|
||||
* [#245](https://github.com/Icinga/icinga-powershell-framework/pull/245) Fixes loading of `.pfx` certificates by properly checking the file type
|
||||
* [#265](https://github.com/Icinga/icinga-powershell-framework/pull/265) Fixes `Test-Numeric` to now accept negative numeric values and als fixes errors, causing `.` to be allowed multiple times. `ConvertFrom-TimeSpan` now properly prints on negative values if the time provided is positive or negative and also prints microseconds as `us` in case the value is loer than `1ms`
|
||||
* [#265](https://github.com/Icinga/icinga-powershell-framework/pull/265) Fixes `Test-Numeric` to now accept negative numeric values and als fixes errors, causing `.` to be allowed multiple times. `ConvertFrom-TimeSpan` now properly prints on negative values if the time provided is positive or negative and also prints microseconds as `us` in case the value is lower than `1ms`
|
||||
* [#269](https://github.com/Icinga/icinga-powershell-framework/pull/269) Fixes unhandled exception on `Set-IcingaCacheData`, as the `-ErrorAction Stop` argument was not set and therefor the function never halted on errors
|
||||
* [#272](https://github.com/Icinga/icinga-powershell-framework/pull/272) Fixes invalid unit conversion, in case first char of a string is matching time metrics
|
||||
|
||||
|
|
@ -438,7 +438,7 @@ Check Command configuration generated by Icinga for Windows 1.2.0 require Icinga
|
|||
|
||||
### Bugfixes
|
||||
|
||||
* Fixed wrong URL for stable plugin repository (refered to Framework instead of Plugins)
|
||||
* Fixed wrong URL for stable plugin repository (referred to Framework instead of Plugins)
|
||||
|
||||
## 1.0.0 RC2 (2019-12-13)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
# Framework Eventlog Documentation
|
||||
# Framework EventLog Documentation
|
||||
|
||||
Below you will find a list of EventId's which are exported by this module. The short and detailed message are both written directly into the eventlog. This documentation shall simply provide a summary of available EventId's
|
||||
Below you will find a list of EventId's which are exported by this module. The short and detailed message are both written directly into the EventLog. This documentation shall simply provide a summary of available EventId's
|
||||
|
||||
## Event Id 1000
|
||||
|
||||
|
|
@ -78,7 +78,7 @@ Below you will find a list of EventId's which are exported by this module. The s
|
|||
|
||||
| Category | Short Message | Detailed Message |
|
||||
| --- | --- | --- |
|
||||
| Warning | Icinga for Windows JEA context not available | The Icinga for Windows JEA session is no longer available and is attempted to be restarted on the system. This could have either happenend due to a crash or a user action, like restarting the WinRM service. |
|
||||
| Warning | Icinga for Windows JEA context not available | The Icinga for Windows JEA session is no longer available and is attempted to be restarted on the system. This could have either happened due to a crash or a user action, like restarting the WinRM service. |
|
||||
|
||||
## Event Id 1550
|
||||
|
||||
|
|
@ -90,7 +90,7 @@ Below you will find a list of EventId's which are exported by this module. The s
|
|||
|
||||
| Category | Short Message | Detailed Message |
|
||||
| --- | --- | --- |
|
||||
| Warning | Invalid authentication credentials provided | A web request for a client was rejected because of invalid formated base64 encoded credentials. |
|
||||
| Warning | Invalid authentication credentials provided | A web request for a client was rejected because of invalid formatted base64 encoded credentials. |
|
||||
|
||||
## Event Id 1552
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ The Icinga PowerShell Framework is shipping wish a bunch of Cmdlets to manage th
|
|||
|
||||
There are many reasons to run the Icinga Agent as a different user than the `NT AUTHORITY\NetworkService` user. One could be additional permissions required, another could be to run the Icinga Agent as own independent user which is entirely managed by your Active Directory or locally available.
|
||||
|
||||
For easier integration the Icinga PowerShell Framework is providing the Cmdlet `Set-IcingaAgentServiceUser`.
|
||||
For easier integration the Icinga PowerShell Framework is providing the Cmdlet `Set-IcingaServiceUser`.
|
||||
|
||||
This Cmdlet ships with 4 arguments which not all of them are mandatory:
|
||||
|
||||
|
|
@ -21,14 +21,14 @@ This Cmdlet ships with 4 arguments which not all of them are mandatory:
|
|||
|
||||
## Changing the Service User
|
||||
|
||||
Now as we are aware on how our Cmdlet `Set-IcingaAgentServiceUser` is working, we can use it to modify our service user.
|
||||
Now as we are aware on how our Cmdlet `Set-IcingaServiceUser` is working, we can use it to modify our service user.
|
||||
|
||||
### Example 1: Change Service User to LocalSystem
|
||||
|
||||
Our first example will simply change the service user from `NT AUTHORITY\NetworkService` to `NT AUTHORITY\SYSTEM`:
|
||||
|
||||
```powershell
|
||||
Set-IcingaAgentServiceUser -User 'NT AUTHORITY\SYSTEM' -SetPermission;
|
||||
Set-IcingaServiceUser -User 'NT AUTHORITY\SYSTEM' -SetPermission;
|
||||
```
|
||||
|
||||
```text
|
||||
|
|
@ -51,7 +51,7 @@ To make things easier and we only require it locally and have not many machines
|
|||
|
||||
```powershell
|
||||
$cred = Get-Credential -Message 'User credentials for icinga2 service:';
|
||||
Set-IcingaAgentServiceUser -User $cred.UserName -Password $cred.Password;
|
||||
Set-IcingaServiceUser -User $cred.UserName -Password $cred.Password;
|
||||
```
|
||||
|
||||
In case we leave the `-SetPermission` argument aside, we simply get the update notification:
|
||||
|
|
@ -73,7 +73,7 @@ To simply resolve this, we can run the command from above again but this time wi
|
|||
|
||||
```powershell
|
||||
$cred = Get-Credential -Message 'User credentials for icinga2 service:';
|
||||
Set-IcingaAgentServiceUser -User $cred.UserName -Password $cred.Password -SetPermission;
|
||||
Set-IcingaServiceUser -User $cred.UserName -Password $cred.Password -SetPermission;
|
||||
```
|
||||
|
||||
```text
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ To make the integration as easy as possible, the Framework is shipping with an I
|
|||
Generating Baskets
|
||||
---
|
||||
|
||||
To automaticly generate the Basket configuration, open a PowerShell terminal and type in
|
||||
To automatically generate the Basket configuration, open a PowerShell terminal and type in
|
||||
|
||||
```powershell
|
||||
Use-Icinga
|
||||
|
|
@ -39,6 +39,6 @@ Once the file is exported, you can navigate to your Icinga Director Basket menu
|
|||
Developer Note
|
||||
---
|
||||
|
||||
The generated Basket configuration will benefit from a detailed documentation of the module and each single argument. Descriptions for arguments are parsed into the Director description field, informing users of what the argument actually does. Furthermore arguments are automaticly mapped to certain object types. A `switch` argument for example will always be rendered with a `yes/no` drop-down-field, while arguments with a fixed set of input types like `Running`, `Stopped`, and so on for services is rendered within a fixed custom list.
|
||||
The generated Basket configuration will benefit from a detailed documentation of the module and each single argument. Descriptions for arguments are parsed into the Director description field, informing users of what the argument actually does. Furthermore arguments are automatically mapped to certain object types. A `switch` argument for example will always be rendered with a `yes/no` drop-down-field, while arguments with a fixed set of input types like `Running`, `Stopped`, and so on for services is rendered within a fixed custom list.
|
||||
|
||||
This will increase the entire usability of the module and prevent you from having to document the a plugin multiple times.
|
||||
|
|
|
|||
|
|
@ -146,14 +146,14 @@ function Add-IcingaAgentServiceTest()
|
|||
# allow to share data collected from this daemon with others
|
||||
$IcingaDaemonData.BackgroundDaemon.Add(
|
||||
'TestIcingaAgentService',
|
||||
[hashtable]::Synchronized(@{})
|
||||
[hashtable]::Synchronized(@{ })
|
||||
);
|
||||
# This will add another hashtable to our previous
|
||||
# TestIcingaAgentService hashtable to store actual service
|
||||
# information
|
||||
$IcingaDaemonData.BackgroundDaemon.TestIcingaAgentService.Add(
|
||||
'ServiceState',
|
||||
[hashtable]::Synchronized(@{})
|
||||
[hashtable]::Synchronized(@{ })
|
||||
);
|
||||
}
|
||||
```
|
||||
|
|
@ -179,14 +179,14 @@ function Add-IcingaAgentServiceTest()
|
|||
# allow to share data collected from this daemon with others
|
||||
$IcingaDaemonData.BackgroundDaemon.Add(
|
||||
'TestIcingaAgentService',
|
||||
[hashtable]::Synchronized(@{})
|
||||
[hashtable]::Synchronized(@{ })
|
||||
);
|
||||
# This will add another hashtable to our previous
|
||||
# TestIcingaAgentService hashtable to store actual service
|
||||
# information
|
||||
$IcingaDaemonData.BackgroundDaemon.TestIcingaAgentService.Add(
|
||||
'ServiceState',
|
||||
[hashtable]::Synchronized(@{})
|
||||
[hashtable]::Synchronized(@{ })
|
||||
);
|
||||
|
||||
# Keep our code executed as long as the PowerShell service is
|
||||
|
|
@ -197,7 +197,7 @@ function Add-IcingaAgentServiceTest()
|
|||
}
|
||||
```
|
||||
|
||||
*ALWAYS* ensure you add some sort for `sleep` at the end of the `while` loop to allow your CPU some breaks. If you do not do this, you might suffer from high CPU loads. The `sleep duration` interval can depend either on a simple CPU cycle break or by telling the daemon to execute tasks only in certain intervalls. In our case we wish to execute the daemon every `5 seconds`.
|
||||
*ALWAYS* ensure you add some sort for `sleep` at the end of the `while` loop to allow your CPU some breaks. If you do not do this, you might suffer from high CPU loads. The `sleep duration` interval can depend either on a simple CPU cycle break or by telling the daemon to execute tasks only in certain interval. In our case we wish to execute the daemon every `5 seconds`.
|
||||
|
||||
```powershell
|
||||
function Add-IcingaAgentServiceTest()
|
||||
|
|
@ -216,14 +216,14 @@ function Add-IcingaAgentServiceTest()
|
|||
# allow to share data collected from this daemon with others
|
||||
$IcingaDaemonData.BackgroundDaemon.Add(
|
||||
'TestIcingaAgentService',
|
||||
[hashtable]::Synchronized(@{})
|
||||
[hashtable]::Synchronized(@{ })
|
||||
);
|
||||
# This will add another hashtable to our previous
|
||||
# TestIcingaAgentService hashtable to store actual service
|
||||
# information
|
||||
$IcingaDaemonData.BackgroundDaemon.TestIcingaAgentService.Add(
|
||||
'ServiceState',
|
||||
[hashtable]::Synchronized(@{})
|
||||
[hashtable]::Synchronized(@{ })
|
||||
);
|
||||
|
||||
# Keep our code executed as long as the PowerShell service is
|
||||
|
|
@ -257,14 +257,14 @@ function Add-IcingaAgentServiceTest()
|
|||
# allow to share data collected from this daemon with others
|
||||
$IcingaDaemonData.BackgroundDaemon.Add(
|
||||
'TestIcingaAgentService',
|
||||
[hashtable]::Synchronized(@{})
|
||||
[hashtable]::Synchronized(@{ })
|
||||
);
|
||||
# This will add another hashtable to our previous
|
||||
# TestIcingaAgentService hashtable to store actual service
|
||||
# information
|
||||
$IcingaDaemonData.BackgroundDaemon.TestIcingaAgentService.Add(
|
||||
'ServiceState',
|
||||
[hashtable]::Synchronized(@{})
|
||||
[hashtable]::Synchronized(@{ })
|
||||
);
|
||||
|
||||
# Initialise our error counter variable
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ With the [Icinga PowerShell Framework](https://icinga.com/docs/windows/latest) y
|
|||
|
||||
## File Structure
|
||||
|
||||
For plugins we will have to distinguish between general components. The plugin file itself with the Cmdlet and the general check/treshold comparison and possible data providers, delivery the content for our modules. If you for example write plugins for your application monitoring and you require different functions to collect these information, the way to gois to separate the collector functions from the plugin itself.
|
||||
For plugins we will have to distinguish between general components. The plugin file itself with the Cmdlet and the general check/threshold comparison and possible data providers, delivery the content for our modules. If you for example write plugins for your application monitoring and you require different functions to collect these information, the way to go is to separate the collector functions from the plugin itself.
|
||||
|
||||
This will result in the following file structure
|
||||
|
||||
|
|
@ -46,9 +46,9 @@ C:\Program Files\WindowsPowerShell\Modules
|
|||
|
||||
Now create a new folder with the name `icinga-powershell-plugintutorial` and navigate into it.
|
||||
|
||||
As we require a `psm1` file which contains our code, we will create a new file with the name `icinga-powershell-plugintutorial.psm1`. This will allow the PowerShell autoloader to load the module automaticly.
|
||||
As we require a `psm1` file which contains our code, we will create a new file with the name `icinga-powershell-plugintutorial.psm1`. This will allow the PowerShell autoloader to load the module automatically.
|
||||
|
||||
**Note:** It could be possible, depending on your [execution policies](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.security/set-executionpolicy?view=powershell-6), that your module is not loaded properly. If this is the case, you can try to unblock the file by opening a PowerShell and use the `Unblock-File` Cmdelet
|
||||
**Note:** It could be possible, depending on your [execution policies](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.security/set-executionpolicy?view=powershell-6), that your module is not loaded properly. If this is the case, you can try to unblock the file by opening a PowerShell and use the `Unblock-File` Cmdlet
|
||||
|
||||
```powershell
|
||||
Unblock-File -Path 'C:\Program Files\WindowsPowerShell\Modules\icinga-powershell-plugintutorial\icinga-powershell-plugintutorial.psm1'
|
||||
|
|
@ -58,7 +58,7 @@ Unblock-File -Path 'C:\Program Files\WindowsPowerShell\Modules\icinga-powershell
|
|||
|
||||
Once the module files are created and unblocked, we can start testing if the autoloader is properly working and our module is detected.
|
||||
|
||||
For this open the file `icinga-powershell-plugintutorial.psm1` in your prefered editor and add the following code snippet
|
||||
For this open the file `icinga-powershell-plugintutorial.psm1` in your preferred editor and add the following code snippet
|
||||
|
||||
```powershell
|
||||
function Test-MyIcingaPluginTutorialCommand()
|
||||
|
|
@ -107,7 +107,7 @@ At first we will create a variable inside our `Start-IcingaAgentServiceTest` fun
|
|||
```powershell
|
||||
function Invoke-IcingaCheckTutorial()
|
||||
{
|
||||
# Create our arguments we can use to parese thresholds
|
||||
# Create our arguments we can use to parse thresholds
|
||||
# Example: Invoke-IcingaCheckTutorial -Warning 10 -Critical 30
|
||||
param (
|
||||
$Warning = $null,
|
||||
|
|
@ -144,12 +144,12 @@ Our tutorial plugin will now output the current status, the name, performance da
|
|||
|
||||
### Optional Performance Data
|
||||
|
||||
To make performance data optional on user input, we can now add another argument to our paramter list and update our check result object to use this argument
|
||||
To make performance data optional on user input, we can now add another argument to our parameter list and update our check result object to use this argument
|
||||
|
||||
```powershell
|
||||
function Invoke-IcingaCheckTutorial()
|
||||
{
|
||||
# Create our arguments we can use to parese thresholds
|
||||
# Create our arguments we can use to parse thresholds
|
||||
# Example: Invoke-IcingaCheckTutorial -Warning 10 -Critical 30
|
||||
param (
|
||||
$Warning = $null,
|
||||
|
|
@ -189,7 +189,7 @@ Now as the basic skeleton is ready, we can dive into the actual check object. In
|
|||
```powershell
|
||||
function Invoke-IcingaCheckTutorial()
|
||||
{
|
||||
# Create our arguments we can use to parese thresholds
|
||||
# Create our arguments we can use to parse thresholds
|
||||
# Example: Invoke-IcingaCheckTutorial -Warning 10 -Critical 30
|
||||
param (
|
||||
$Warning = $null,
|
||||
|
|
@ -226,18 +226,18 @@ powershell -C { Use-Icinga; Invoke-IcingaCheckTutorial }
|
|||
0
|
||||
```
|
||||
|
||||
### Compare Value with Tresholds
|
||||
### Compare Value with Thresholds
|
||||
|
||||
Now as we are holding a value inside our check object, we can start to compare it with our `Warning` and `Critical` tresholds. There are a bunch of functions inside the check object avaialble for this which can be found in the [check object documentation](01-New-IcingaCheck.md).
|
||||
Now as we are holding a value inside our check object, we can start to compare it with our `Warning` and `Critical` thresholds. There are a bunch of functions inside the check object available for this which can be found in the [check object documentation](01-New-IcingaCheck.md).
|
||||
|
||||
For most plugins the generic approach will do just fine. This one will ensure we can use the Nagios/Icinga treshold syntax to compare values more dynamicly and add ranges support. (See also [Icinga Plugins](https://icinga.com/docs/windows/latest/plugins/doc/10-Icinga-Plugins/))
|
||||
For most plugins the generic approach will do just fine. This one will ensure we can use the Nagios/Icinga threshold syntax to compare values more dynamically and add ranges support. (See also [Icinga Plugins](https://icinga.com/docs/windows/latest/plugins/doc/10-Icinga-Plugins/))
|
||||
|
||||
The two functions we will use for this are `WarnOutOfRange` and `CritOutOfRange`.
|
||||
|
||||
```powershell
|
||||
function Invoke-IcingaCheckTutorial()
|
||||
{
|
||||
# Create our arguments we can use to parese thresholds
|
||||
# Create our arguments we can use to parse thresholds
|
||||
# Example: Invoke-IcingaCheckTutorial -Warning 10 -Critical 30
|
||||
param (
|
||||
$Warning = $null,
|
||||
|
|
@ -291,14 +291,14 @@ powershell -C { Use-Icinga; Invoke-IcingaCheckTutorial -Warning 20 -Critical 30
|
|||
|
||||
Now it is time to combine multiple check objects into one check package. Our basic plugin works just fine, but maybe we wish to compare multiple values for multiple checks. To do so, we will create another `check object` and one `check package object`.
|
||||
|
||||
Dont forget to add the compare functions `WarnOutOfRange` and `CritOutOfRange` for the new `check object`!
|
||||
Don't forget to add the compare functions `WarnOutOfRange` and `CritOutOfRange` for the new `check object`!
|
||||
|
||||
Last but not least we will modify our `New-IcingaCheckResult` fuction to use the `check package` instead of our old `check object`
|
||||
Last but not least we will modify our `New-IcingaCheckResult` function to use the `check package` instead of our old `check object`
|
||||
|
||||
```powershell
|
||||
function Invoke-IcingaCheckTutorial()
|
||||
{
|
||||
# Create our arguments we can use to parese thresholds
|
||||
# Create our arguments we can use to parse thresholds
|
||||
# Example: Invoke-IcingaCheckTutorial -Warning 10 -Critical 30
|
||||
param (
|
||||
$Warning = $null,
|
||||
|
|
@ -328,8 +328,8 @@ function Invoke-IcingaCheckTutorial()
|
|||
# or store the result inside a variable, as the check
|
||||
# object is otherwise written into our plugin output
|
||||
$Check.WarnOutOfRange($Warning).CritOutOfRange($Critical) | Out-Null;
|
||||
# Dont forget to add our comparison for the second check with
|
||||
# the identical tresholds. If you want to, you could compare
|
||||
# Don't forget to add our comparison for the second check with
|
||||
# the identical thresholds. If you want to, you could compare
|
||||
# them to different arguments
|
||||
$Check2.WarnOutOfRange($Warning).CritOutOfRange($Critical) | Out-Null;
|
||||
|
||||
|
|
@ -370,12 +370,12 @@ powershell -C { Use-Icinga; Invoke-IcingaCheckTutorial -Warning 20 -Critical 30
|
|||
|
||||
### Package Operators
|
||||
|
||||
As you see, the plugin output is `Ok` while clearly it should throw `Critical`. What we are missing is a comparing operator, telling the package how to count each assiged check. We have several operators on our hand:
|
||||
As you see, the plugin output is `Ok` while clearly it should throw `Critical`. What we are missing is a comparing operator, telling the package how to count each assigned check. We have several operators on our hand:
|
||||
|
||||
* `-OperatorMin <number>` with `<number>` amount of checks require to be ok for the package to be ok
|
||||
* `-OperatorMax <number>` with `<number>` amount of checks require to be ok for the package to be ok
|
||||
* `-OperatorAnd` for all checks requiring to be ok for the package to be ok
|
||||
* `-OperatorOr` for atleast one check requiring to be ok for the package to be ok
|
||||
* `-OperatorOr` for at least one check requiring to be ok for the package to be ok
|
||||
* `-OperatorNone` for all checks to be `not` ok for the package to be ok
|
||||
|
||||
You can only use one operator per check package, a combination is not possible.
|
||||
|
|
@ -385,7 +385,7 @@ On our example we will use the `-OperatorAnd` to ensure all checks have to be ok
|
|||
```powershell
|
||||
function Invoke-IcingaCheckTutorial()
|
||||
{
|
||||
# Create our arguments we can use to parese thresholds
|
||||
# Create our arguments we can use to parse thresholds
|
||||
# Example: Invoke-IcingaCheckTutorial -Warning 10 -Critical 30
|
||||
param (
|
||||
$Warning = $null,
|
||||
|
|
@ -415,8 +415,8 @@ function Invoke-IcingaCheckTutorial()
|
|||
# or store the result inside a variable, as the check
|
||||
# object is otherwise written into our plugin output
|
||||
$Check.WarnOutOfRange($Warning).CritOutOfRange($Critical) | Out-Null;
|
||||
# Dont forget to add our comparison for the second check with
|
||||
# the identical tresholds. If you want to, you could compare
|
||||
# Don't forget to add our comparison for the second check with
|
||||
# the identical thresholds. If you want to, you could compare
|
||||
# them to different arguments
|
||||
$Check2.WarnOutOfRange($Warning).CritOutOfRange($Critical) | Out-Null;
|
||||
|
||||
|
|
@ -464,11 +464,11 @@ As you can see our package is now critical, outputting each check which is `not`
|
|||
[CRITICAL] Tutorial, Tutorial 2
|
||||
```
|
||||
|
||||
inside the short plugin output to ensure we have a quick overview within Icinga Web 2, telling us which checks are failling.
|
||||
inside the short plugin output to ensure we have a quick overview within Icinga Web 2, telling us which checks are failing.
|
||||
|
||||
### Increasing Verbosity
|
||||
|
||||
In case our checks are ok, they are not printed by default to keep the view as little as possible. We can test this by executing the plugin without tresholds
|
||||
In case our checks are ok, they are not printed by default to keep the view as little as possible. We can test this by executing the plugin without thresholds
|
||||
|
||||
```powershell
|
||||
powershell -C { Use-Icinga; Invoke-IcingaCheckTutorial }
|
||||
|
|
@ -487,7 +487,7 @@ In addition, we will parse the new `$Verbosity` as argument to our `check packag
|
|||
```powershell
|
||||
function Invoke-IcingaCheckTutorial()
|
||||
{
|
||||
# Create our arguments we can use to parese thresholds
|
||||
# Create our arguments we can use to parse thresholds
|
||||
# Example: Invoke-IcingaCheckTutorial -Warning 10 -Critical 30
|
||||
param (
|
||||
$Warning = $null,
|
||||
|
|
@ -520,8 +520,8 @@ function Invoke-IcingaCheckTutorial()
|
|||
# or store the result inside a variable, as the check
|
||||
# object is otherwise written into our plugin output
|
||||
$Check.WarnOutOfRange($Warning).CritOutOfRange($Critical) | Out-Null;
|
||||
# Dont forget to add our comparison for the second check with
|
||||
# the identical tresholds. If you want to, you could compare
|
||||
# Don't forget to add our comparison for the second check with
|
||||
# the identical thresholds. If you want to, you could compare
|
||||
# them to different arguments
|
||||
$Check2.WarnOutOfRange($Warning).CritOutOfRange($Critical) | Out-Null;
|
||||
|
||||
|
|
@ -550,7 +550,7 @@ function Invoke-IcingaCheckTutorial()
|
|||
}
|
||||
```
|
||||
|
||||
If we now exectue the plugin with `Verbosity` and the value `2`, every single check will be printed, even when the check itself is Ok
|
||||
If we now execute the plugin with `Verbosity` and the value `2`, every single check will be printed, even when the check itself is Ok
|
||||
|
||||
```powershell
|
||||
powershell -C { Use-Icinga; Invoke-IcingaCheckTutorial -Verbosity 2 }
|
||||
|
|
@ -578,7 +578,7 @@ You simply have to ensure you are adding `checks` and `check packages` correctly
|
|||
|
||||
### Icinga Configuration
|
||||
|
||||
Now as we are done with writing our plugin, it is time to test it inside Icinga 2. Instead of having to write an `Icinga Director` command configuration yourself, we can use an integrated Framework Cmdlet to generate a `Basket` file for us which can be imorted into the `Icinga Director`.
|
||||
Now as we are done with writing our plugin, it is time to test it inside Icinga 2. Instead of having to write an `Icinga Director` command configuration yourself, we can use an integrated Framework Cmdlet to generate a `Basket` file for us which can be imported into the `Icinga Director`.
|
||||
|
||||
```powershell
|
||||
Get-IcingaCheckCommandConfig -CheckName 'Invoke-IcingaCheckTutorial' -OutDirectory 'C:\users\public';
|
||||
|
|
|
|||
|
|
@ -1,28 +1,28 @@
|
|||
# Developer Guide: Using EventLog Outputs
|
||||
|
||||
Windows provides an easy way for managing log content by simply writing it into the eventlog. For this developers can create an own application space to better filter events for the user and to provide context.
|
||||
Windows provides an easy way for managing log content by simply writing it into the EventLog. For this developers can create an own application space to better filter events for the user and to provide context.
|
||||
|
||||
The Icinga PowerShell Framework is fully supporting this by providing Cmdlets to write events into the eventlog with proper severities, ids and messages. For troubleshooting it is also supported to dump object informations.
|
||||
The Icinga PowerShell Framework is fully supporting this by providing Cmdlets to write events into the EventLog with proper severities, ids and messages. For troubleshooting it is also supported to dump object informations.
|
||||
|
||||
## General Usage Of EventLog Writer
|
||||
|
||||
There are two Cmdlets available dealing with the writing into the eventlog. One is for debugging purpose only and the other one is for handling real events.
|
||||
There are two Cmdlets available dealing with the writing into the EventLog. One is for debugging purpose only and the other one is for handling real events.
|
||||
|
||||
To simply write debugging information into the eventlog you can use `Write-IcingaDebugMessage` which is fully explained below. There is no special configuration required for this Cmdlet.
|
||||
To simply write debugging information into the EventLog you can use `Write-IcingaDebugMessage` which is fully explained below. There is no special configuration required for this Cmdlet.
|
||||
|
||||
The more important Cmdlet is `Write-IcingaEventMessage` which provides some guidelines developers will have to follow which explained below.
|
||||
|
||||
### Providing EventLog Content
|
||||
|
||||
Unlike other logging mechanisms, the eventlog writer was designed to achieve multiple goals at once:
|
||||
Unlike other logging mechanisms, the EventLog writer was designed to achieve multiple goals at once:
|
||||
|
||||
* Quick and easy to use in projects
|
||||
* Flexible extendable for custom modules
|
||||
* Providing documentation for occuring events including the ability to export markdown files
|
||||
* Providing documentation for occurring events including the ability to export markdown files
|
||||
|
||||
To make use of all these topics, eventlog entries have to be configured for each module within an own function. These functions will have to return a `hashtable` that provides an unique name as `namespace`, followed by event id `hashtables` containing the `EntryType`, a `Message`, additional `Details` and the `EventId`. Please note that `all` of these values are mandatory!
|
||||
To make use of all these topics, EventLog entries have to be configured for each module within an own function. These functions will have to return a `hashtable` that provides an unique name as `namespace`, followed by event id `hashtables` containing the `EntryType`, a `Message`, additional `Details` and the `EventId`. Please note that `all` of these values are mandatory!
|
||||
|
||||
An eventlog hashtable should then look like this:
|
||||
An EventLog hashtable should then look like this:
|
||||
|
||||
```powershell
|
||||
[hashtable]$EventLogEntries = @{
|
||||
|
|
@ -37,11 +37,11 @@ An eventlog hashtable should then look like this:
|
|||
}
|
||||
```
|
||||
|
||||
In this case `MyCustomNamespace` is the namespace we later refer to. This will prevent modules and possible indentical event ids to get into each others way. Within our `MyCustomNamespace` we will then add another `hashtable` which uses an `EventId` as key, followed by another hashtable containing the actual content of the event.
|
||||
In this case `MyCustomNamespace` is the namespace we later refer to. This will prevent modules and possible identical event ids to get into each others way. Within our `MyCustomNamespace` we will then add another `hashtable` which uses an `EventId` as key, followed by another hashtable containing the actual content of the event.
|
||||
|
||||
#### EntryType
|
||||
|
||||
The `EntryType` will provide the severity which is being written into the eventlog. The following entries are supported:
|
||||
The `EntryType` will provide the severity which is being written into the EventLog. The following entries are supported:
|
||||
|
||||
* Information
|
||||
* SuccessAudit
|
||||
|
|
@ -55,17 +55,17 @@ The `Message` should be a short summary of the event for a first impression. Ple
|
|||
|
||||
#### Details
|
||||
|
||||
The details section should provide a more detailed explanation on what went wrong and how the user could resolve this issue or where to look for additional help. This entry is added to the eventlog in addition but seperated with newlines from the message itself.
|
||||
The details section should provide a more detailed explanation on what went wrong and how the user could resolve this issue or where to look for additional help. This entry is added to the EventLog in addition but separated with newlines from the message itself.
|
||||
|
||||
#### EventId
|
||||
|
||||
The id the message is being added into the eventlog. This will allow the user to easier filter for certain events and check if a specific event or even an error occured. For developers the Id range should be between `3000` and `9000`.
|
||||
The id the message is being added into the EventLog. This will allow the user to easier filter for certain events and check if a specific event or even an error occurred. For developers the Id range should be between `3000` and `9000`.
|
||||
|
||||
### Registering EventLog Content
|
||||
|
||||
To register your own eventlog content you will have to add a function following a naming scheme as `namespace` which must always be callable once the module is loaded: `Register-IcingaEventLogMessages{x}`
|
||||
To register your own EventLog content you will have to add a function following a naming scheme as `namespace` which must always be callable once the module is loaded: `Register-IcingaEventLogMessages{x}`
|
||||
|
||||
Replace the `{x}` with a unique name that matches your module name for example, ensuring that this name is **not** taken by another module. Once the Icinga PowerShell Framework is initialised, it will lookup all functions within this namespace and execute them to fetch the eventlog data provided as hashtable. An example for our `MyCustomNamespace` which would be added to our custom module could look like this:
|
||||
Replace the `{x}` with a unique name that matches your module name for example, ensuring that this name is **not** taken by another module. Once the Icinga PowerShell Framework is initialised, it will lookup all functions within this namespace and execute them to fetch the EventLog data provided as hashtable. An example for our `MyCustomNamespace` which would be added to our custom module could look like this:
|
||||
|
||||
```powershell
|
||||
function Register-IcingaEventLogMessagesMyCustomNamespace()
|
||||
|
|
@ -81,7 +81,7 @@ function Register-IcingaEventLogMessagesMyCustomNamespace()
|
|||
2100 = @{
|
||||
'EntryType' = 'Warning';
|
||||
'Message' = 'Failed to add namespace configuration for executed commands, as previous commands are reporting identical namespace identifiers';
|
||||
'Details' = 'This warning occures while the REST-Api is trying to auto-load different ressources automatically to provide for example inventory information or any other auto-loaded configurations. Please review your installed modules, check the detailed description which moules and Cmdllets caused this conflict and either resolve it or get in contact with the corresponding developers.';
|
||||
'Details' = 'This warning occurs while the REST-Api is trying to auto-load different resources automatically to provide for example inventory information or any other auto-loaded configurations. Please review your installed modules, check the detailed description which modules and Cmdlets caused this conflict and either resolve it or get in contact with the corresponding developers.';
|
||||
'EventId' = 2100;
|
||||
};
|
||||
}
|
||||
|
|
@ -91,7 +91,7 @@ function Register-IcingaEventLogMessagesMyCustomNamespace()
|
|||
|
||||
### Using EventLog Writer
|
||||
|
||||
Now as our eventlog configuration is complete, we can start using it. For this we will use the Cmdlet `Write-IcingaEventMessage` and provide our `Namespace` for referencing the correct eventlog content as well as the `Eventid` for fetching and writing the `EntryType`, `Message` and `Details` as configured into the eventlog.
|
||||
Now as our EventLog configuration is complete, we can start using it. For this we will use the Cmdlet `Write-IcingaEventMessage` and provide our `Namespace` for referencing the correct EventLog content as well as the `EventId` for fetching and writing the `EntryType`, `Message` and `Details` as configured into the EventLog.
|
||||
|
||||
Following our above example, the call will look like this:
|
||||
|
||||
|
|
@ -107,20 +107,20 @@ Write-IcingaEventMessage -EventId 2000 -Namespace 'MyCustomNamespace' -Objects '
|
|||
|
||||
### Using EventLog Debugging
|
||||
|
||||
Debugging by using the eventlog is simpler, as it will not require unique ids or any sort of configuration. To write debug message into the eventlog you can use `Write-IcingaDebugMessage`. Instead of providing a `Namespace` or an `EventId`, you can simply add a `Message` including `Objects`. All events are written into the eventlog with id `1000` and severity `information`.
|
||||
Debugging by using the EventLog is simpler, as it will not require unique ids or any sort of configuration. To write debug message into the EventLog you can use `Write-IcingaDebugMessage`. Instead of providing a `Namespace` or an `EventId`, you can simply add a `Message` including `Objects`. All events are written into the EventLog with id `1000` and severity `information`.
|
||||
|
||||
```powershell
|
||||
Write-IcingaDebugMessage -Message 'This is a debug message being printed into the eventlog' -Objects 'Additional content as text', (Get-Random));
|
||||
Write-IcingaDebugMessage -Message 'This is a debug message being printed into the EventLog' -Objects 'Additional content as text', (Get-Random));
|
||||
```
|
||||
|
||||
**Note:** Debug messages will only be printed if the `debug mode` of the Icinga PowerShell Framework is enabled. To enable the debug mode, you can use `Enable-IcingaFrameworkDebugMode` and to disable it `Disable-IcingaFrameworkDebugMode`. To check if the mode is enabled or disabled you can use `Get-IcingaFrameworkDebugMode`.
|
||||
|
||||
### Exporting EventLog Content As Markdown
|
||||
|
||||
A huge benefit of the implementation we choose is the possibility to export the eventlog configuration as markdown, making it easier for providing them on GitHub for example. For this we can use the Cmdlet `Publish-IcingaEventlogDocumentation` and provide the namespace for the eventlog to export and a destination file.
|
||||
A huge benefit of the implementation we choose is the possibility to export the EventLog configuration as markdown, making it easier for providing them on GitHub for example. For this we can use the Cmdlet `Publish-IcingaEventLogDocumentation` and provide the namespace for the EventLog to export and a destination file.
|
||||
|
||||
```powershell
|
||||
Publish-IcingaEventlogDocumentation -Namespace 'Framework' -OutFile 'C:\users\public\eventlog-doc.md':
|
||||
Publish-IcingaEventLogDocumentation -Namespace 'Framework' -OutFile 'C:\users\public\EventLog-doc.md':
|
||||
```
|
||||
|
||||
An example on how the exported result looks like can be found on the [Framework Eventlog Documentation](../100-General/20-Eventlog.md).
|
||||
An example on how the exported result looks like can be found on the [Framework EventLog Documentation](../100-General/20-EventLog.md).
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ The user you are running this command as does not have permission to access the
|
|||
|
||||
## Easy fetching of data
|
||||
|
||||
To ensure the above mentioned funtionality is made easy, we added the wrapper function `Get-IcingaWindowsInformation`. This function will by default use the `Get-CimInstance` Cmdlet and as fallback `Get-WmiObject`:
|
||||
To ensure the above mentioned functionality is made easy, we added the wrapper function `Get-IcingaWindowsInformation`. This function will by default use the `Get-CimInstance` Cmdlet and as fallback `Get-WmiObject`:
|
||||
|
||||
```powershell
|
||||
Get-IcingaWindowsInformation Win32_ComputerSystem;
|
||||
|
|
@ -108,7 +108,7 @@ The provided class name you try to fetch with Get-CimInstance is not known on th
|
|||
|
||||
## Usage of filters
|
||||
|
||||
As for `Get-CimInstance` or `Get-WmiObject` you can also use the `-Filter` argument to search for certain content wihtin the return output and only return specific content:
|
||||
As for `Get-CimInstance` or `Get-WmiObject` you can also use the `-Filter` argument to search for certain content within the return output and only return specific content:
|
||||
|
||||
```powershell
|
||||
Use-Icinga;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<#
|
||||
.Synopsis
|
||||
Icinga PowerShell Module - Powerfull PowerShell Framework for monitoring Windows Systems
|
||||
Icinga PowerShell Module - Powerful PowerShell Framework for monitoring Windows Systems
|
||||
.DESCRIPTION
|
||||
More Information on https://github.com/Icinga/icinga-powershell-framework
|
||||
.EXAMPLE
|
||||
|
|
@ -127,7 +127,7 @@ function Write-IcingaFrameworkCodeCache()
|
|||
Remove-IcingaFrameworkDependencyFile;
|
||||
}
|
||||
|
||||
function Publish-IcingaEventlogDocumentation()
|
||||
function Publish-IcingaEventLogDocumentation()
|
||||
{
|
||||
param(
|
||||
[string]$Namespace,
|
||||
|
|
@ -135,12 +135,12 @@ function Publish-IcingaEventlogDocumentation()
|
|||
);
|
||||
|
||||
[string]$DocContent = [string]::Format(
|
||||
'# {0} Eventlog Documentation',
|
||||
'# {0} EventLog Documentation',
|
||||
$Namespace
|
||||
);
|
||||
$DocContent += New-IcingaNewLine;
|
||||
$DocContent += New-IcingaNewLine;
|
||||
$DocContent += "Below you will find a list of EventId's which are exported by this module. The short and detailed message are both written directly into the eventlog. This documentation shall simply provide a summary of available EventId's";
|
||||
$DocContent += "Below you will find a list of EventId's which are exported by this module. The short and detailed message are both written directly into the EventLog. This documentation shall simply provide a summary of available EventId's";
|
||||
|
||||
$SortedArray = $IcingaEventLogEnums[$Namespace].Keys.GetEnumerator() | Sort-Object;
|
||||
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ function Get-IcingaDirectorSelfServiceTicket()
|
|||
break;
|
||||
};
|
||||
500 {
|
||||
$ErrorMessage = 'Failed to fetch certificate ticket for this host over Self-Service API. Please check that your Icinga CA is running, you have configured a Ticketsalt and that your Icinga Director has enough permissions to communicate with the Icinga 2 API for generating tickets.';
|
||||
$ErrorMessage = 'Failed to fetch certificate ticket for this host over Self-Service API. Please check that your Icinga CA is running, you have configured a TicketSalt and that your Icinga Director has enough permissions to communicate with the Icinga 2 API for generating tickets.';
|
||||
break;
|
||||
};
|
||||
901 {
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Register the current host wihtin the Icinga Director by using the
|
||||
Register the current host within the Icinga Director by using the
|
||||
Self-Service API and return the host key
|
||||
.DESCRIPTION
|
||||
This function will register the current host within the Icinga Director in case
|
||||
it is not already registered and returns the host key for storing it on disk
|
||||
to allow the host to fetch detailed configurations like zones and endppoints
|
||||
to allow the host to fetch detailed configurations like zones and endpoints
|
||||
.FUNCTIONALITY
|
||||
Register a host within the Icinga Director by using the Self-Service API
|
||||
.EXAMPLE
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ function New-IcingaPowerShellConfigItem()
|
|||
);
|
||||
|
||||
if ($null -eq $ConfigValue) {
|
||||
$ConfigValue = (New-Object -TypeName PSOBject);
|
||||
$ConfigValue = (New-Object -TypeName PSObject);
|
||||
}
|
||||
|
||||
$ConfigObject | Add-Member -MemberType NoteProperty -Name $ConfigKey -Value $ConfigValue;
|
||||
|
|
|
|||
|
|
@ -101,8 +101,8 @@ function New-IcingaForWindowsComponent()
|
|||
Add-Content -Path $InvokeFunctionFile -Value '{';
|
||||
Add-Content -Path $InvokeFunctionFile -Value ' # Do not modify the param section';
|
||||
Add-Content -Path $InvokeFunctionFile -Value ' param (';
|
||||
Add-Content -Path $InvokeFunctionFile -Value ' [Hashtable]$Request = @{},';
|
||||
Add-Content -Path $InvokeFunctionFile -Value ' [Hashtable]$Connection = @{},';
|
||||
Add-Content -Path $InvokeFunctionFile -Value ' [Hashtable]$Request = @{ },';
|
||||
Add-Content -Path $InvokeFunctionFile -Value ' [Hashtable]$Connection = @{ },';
|
||||
Add-Content -Path $InvokeFunctionFile -Value ' $IcingaGlobals,';
|
||||
Add-Content -Path $InvokeFunctionFile -Value ' [string]$ApiVersion = $null';
|
||||
Add-Content -Path $InvokeFunctionFile -Value ' );'
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
function Publish-IcingaEventlogDocumentation()
|
||||
function Publish-IcingaEventLogDocumentation()
|
||||
{
|
||||
param(
|
||||
[string]$Namespace,
|
||||
|
|
@ -6,12 +6,12 @@ function Publish-IcingaEventlogDocumentation()
|
|||
);
|
||||
|
||||
[string]$DocContent = [string]::Format(
|
||||
'# {0} Eventlog Documentation',
|
||||
'# {0} EventLog Documentation',
|
||||
$Namespace
|
||||
);
|
||||
$DocContent += New-IcingaNewLine;
|
||||
$DocContent += New-IcingaNewLine;
|
||||
$DocContent += "Below you will find a list of EventId's which are exported by this module. The short and detailed message are both written directly into the eventlog. This documentation shall simply provide a summary of available EventId's";
|
||||
$DocContent += "Below you will find a list of EventId's which are exported by this module. The short and detailed message are both written directly into the EventLog. This documentation shall simply provide a summary of available EventId's";
|
||||
|
||||
$SortedArray = $IcingaEventLogEnums[$Namespace].Keys.GetEnumerator() | Sort-Object;
|
||||
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ function Install-IcingaForWindowsService()
|
|||
# a proper user, like 'NT Authority\NetworkService'. For some reason the NetworkService
|
||||
# will not start without this workaround.
|
||||
# Todo: Figure out the reason and fix it properly
|
||||
Set-IcingaAgentServiceUser -User 'LocalSystem' -Service 'icingapowershell' | Out-Null;
|
||||
Set-IcingaServiceUser -User 'LocalSystem' -Service 'icingapowershell' | Out-Null;
|
||||
Restart-IcingaWindowsService;
|
||||
Start-Sleep -Seconds 1;
|
||||
Stop-IcingaWindowsService;
|
||||
|
|
@ -97,7 +97,7 @@ function Install-IcingaForWindowsService()
|
|||
Start-Sleep -Seconds 1;
|
||||
}
|
||||
|
||||
return (Set-IcingaAgentServiceUser -User $User -Password $Password -Service 'icingapowershell');
|
||||
return (Set-IcingaServiceUser -User $User -Password $Password -Service 'icingapowershell');
|
||||
}
|
||||
|
||||
Set-Alias -Name 'Install-IcingaFrameworkService' -Value 'Install-IcingaForWindowsService';
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
.EXAMPLE
|
||||
PS>Install-IcingaFrameworkUpdate -FrameworkUrl 'https://github.com/Icinga/icinga-powershell-framework/archive/v1.0.2.zip';
|
||||
.PARAMETER FrameworkUrl
|
||||
The url to a remote or local ressource pointing directly to a .zip file containing the required files for updating
|
||||
The url to a remote or local resource pointing directly to a .zip file containing the required files for updating
|
||||
.INPUTS
|
||||
System.String
|
||||
.OUTPUTS
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ function Invoke-IcingaNamespaceCmdlets()
|
|||
[string]$Command
|
||||
);
|
||||
|
||||
[Hashtable]$CommandConfig = @{};
|
||||
[Hashtable]$CommandConfig = @{ };
|
||||
|
||||
if ($Command.Contains('*') -eq $FALSE) {
|
||||
$Command = [string]::Format('{0}*', $Command);
|
||||
|
|
|
|||
|
|
@ -5,14 +5,14 @@
|
|||
Icinga 2 configuration files.
|
||||
|
||||
The configuration files are printed within a `config` folder of the
|
||||
specific module and splitted into `director` and `icinga`
|
||||
specific module and split into `director` and `icinga`
|
||||
.DESCRIPTION
|
||||
etches plugins within the namespace `Invoke-IcingaCheck*` for a given
|
||||
component name or the direct path and creates Icinga Director as well as
|
||||
Icinga 2 configuration files.
|
||||
|
||||
The configuration files are printed within a `config` folder of the
|
||||
specific module and splitted into `director` and `icinga`
|
||||
specific module and split into `director` and `icinga`
|
||||
.FUNCTIONALITY
|
||||
Creates Icinga 2 and Icinga Director configuration files for plugins
|
||||
.EXAMPLE
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ function Get-IcingaAgentMSIPackage()
|
|||
$UseVersion = $PackageVersion;
|
||||
}
|
||||
} catch {
|
||||
# Nothing to catch specifically
|
||||
# Nothing to catch specifically
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ function Install-IcingaAgentCertificates()
|
|||
}
|
||||
|
||||
if ((Start-IcingaAgentCertificateProcess -Arguments $arguments) -eq $FALSE) {
|
||||
Write-IcingaConsoleError 'Unable to connect to your provided Icinga CA. Please verify the entered configuration is correct.' `
|
||||
Write-IcingaConsoleError -Message 'Unable to connect to your provided Icinga CA. Please verify the entered configuration is correct.' `
|
||||
'If you are not able to connect to your Icinga CA from this machine, you will have to provide the path' `
|
||||
'to your Icinga ca.crt and use the CA-Proxy certificate handling.';
|
||||
return $FALSE;
|
||||
|
|
@ -150,7 +150,7 @@ function Install-IcingaAgentCertificates()
|
|||
|
||||
return $TRUE;
|
||||
} elseif (-Not [string]::IsNullOrEmpty($CACert)) {
|
||||
if (-Not (Copy-IcingaAgentCACertificate -CAPath $CACert -Desination $CertificateDirectory)) {
|
||||
if (-Not (Copy-IcingaAgentCACertificate -CAPath $CACert -Destination $CertificateDirectory)) {
|
||||
return $FALSE;
|
||||
}
|
||||
Write-IcingaConsoleNotice 'Host-Certificates and ca.crt are present. Please start your Icinga Agent now and manually sign your certificate request on your CA master. You can lookup open requests with "icinga2 ca list"';
|
||||
|
|
@ -209,7 +209,7 @@ function Test-IcingaAgentCertificates()
|
|||
Write-IcingaConsoleNotice 'Your ca.crt is present. No generation or fetching required';
|
||||
return $TRUE;
|
||||
} else {
|
||||
Write-IcingaConsoleWarning 'Your ca.crt is not present. Manuall copy or fetching from your Icinga CA is required.';
|
||||
Write-IcingaConsoleWarning 'Your ca.crt is not present. Manually copy or fetching from your Icinga CA is required.';
|
||||
return $FALSE;
|
||||
}
|
||||
}
|
||||
|
|
@ -261,16 +261,16 @@ function Copy-IcingaAgentCACertificate()
|
|||
{
|
||||
param(
|
||||
[string]$CAPath,
|
||||
[string]$Desination
|
||||
[string]$Destination
|
||||
);
|
||||
|
||||
# Copy ca.crt from local path or network share to certificate path
|
||||
if ((Test-Path $CAPath)) {
|
||||
Copy-Item -Path $CAPath -Destination (Join-Path -Path $Desination -ChildPath 'ca.crt') | Out-Null;
|
||||
Write-IcingaConsoleNotice ([string]::Format('Copied ca.crt from "{0}" to "{1}', $CAPath, $Desination));
|
||||
Copy-Item -Path $CAPath -Destination (Join-Path -Path $Destination -ChildPath 'ca.crt') | Out-Null;
|
||||
Write-IcingaConsoleNotice ([string]::Format('Copied ca.crt from "{0}" to "{1}', $CAPath, $Destination));
|
||||
} else {
|
||||
Set-IcingaTLSVersion;
|
||||
# It could also be a web ressource
|
||||
# It could also be a web resource
|
||||
try {
|
||||
$response = Invoke-IcingaWebRequest $CAPath -UseBasicParsing;
|
||||
[int]$Index = $response.RawContent.IndexOf("`r`n`r`n") + 4;
|
||||
|
|
@ -279,10 +279,10 @@ function Copy-IcingaAgentCACertificate()
|
|||
$Index,
|
||||
$response.RawContent.Length - $Index
|
||||
);
|
||||
Write-IcingaFileSecure -File (Join-Path $Desination -ChildPath 'ca.crt') -Value $CAContent;
|
||||
Write-IcingaConsoleNotice ([string]::Format('Downloaded ca.crt from "{0}" to "{1}', $CAPath, $Desination))
|
||||
Write-IcingaFileSecure -File (Join-Path $Destination -ChildPath 'ca.crt') -Value $CAContent;
|
||||
Write-IcingaConsoleNotice ([string]::Format('Downloaded ca.crt from "{0}" to "{1}', $CAPath, $Destination))
|
||||
} catch {
|
||||
Write-IcingaConsoleError 'Failed to load any provided ca.crt ressource';
|
||||
Write-IcingaConsoleError 'Failed to load any provided ca.crt resource';
|
||||
return $FALSE;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ function Disable-IcingaAgentFeature()
|
|||
return;
|
||||
}
|
||||
|
||||
$Binary = Get-IcingaAGentBinary;
|
||||
$Binary = Get-IcingaAgentBinary;
|
||||
$Process = Start-IcingaProcess -Executable $Binary -Arguments ([string]::Format('feature disable {0}', $Feature));
|
||||
|
||||
if ($Process.ExitCode -ne 0) {
|
||||
|
|
|
|||
|
|
@ -157,7 +157,7 @@ function Start-IcingaDirectorAPIArgumentOverride()
|
|||
$Arguments
|
||||
);
|
||||
|
||||
$NewArguments = @{};
|
||||
$NewArguments = @{ };
|
||||
Write-IcingaConsoleNotice 'Please follow the wizard and manually override all entries you intend to';
|
||||
Write-IcingaConsoleNotice '====';
|
||||
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
Tells the wizard which Icinga Agent version to install. You can provide latest, snapshot or a specific version like 2.11.6
|
||||
Set the value to one mentioned above. Leave it empty to be prompted the wizard question
|
||||
.PARAMETER InstallDir
|
||||
Tells the wizard which directory the Icinga Agent will beinstalled into. Default is `C:\Program Files\ICINGA2`
|
||||
Tells the wizard which directory the Icinga Agent will be installed into. Default is `C:\Program Files\ICINGA2`
|
||||
Set the value to one mentioned above.
|
||||
.PARAMETER AllowVersionChanges
|
||||
Tells the wizard if the Icinga Agent should be updated/downgraded in case the current/target version are not matching
|
||||
|
|
@ -312,7 +312,7 @@ function Start-IcingaAgentInstallWizard()
|
|||
# 'latest' is deprecated starting with 1.1.0
|
||||
if ($AgentVersion -eq 'latest') {
|
||||
$AgentVersion = 'release';
|
||||
Write-IcingaConsoleWarning -Message 'The value "latest" for the argmument "AgentVersion" is deprecated. Please use the value "release" in the future!';
|
||||
Write-IcingaConsoleWarning -Message 'The value "latest" for the argument "AgentVersion" is deprecated. Please use the value "release" in the future!';
|
||||
}
|
||||
|
||||
if ([string]::IsNullOrEmpty($Hostname) -And $null -eq $AutoUseFQDN -And $null -eq $AutoUseHostname) {
|
||||
|
|
@ -477,7 +477,7 @@ function Start-IcingaAgentInstallWizard()
|
|||
}
|
||||
|
||||
if ($null -eq $ConvertEndpointIPConfig -And $CanConnectToParent -eq $TRUE) {
|
||||
if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Do you want to convert parent node(s) connection data to IP adresses?' -Default 'y').result -eq 1) {
|
||||
if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Do you want to convert parent node(s) connection data to IP addresses?' -Default 'y').result -eq 1) {
|
||||
$InstallerArguments += "-ConvertEndpointIPConfig 1";
|
||||
$ConvertEndpointIPConfig = $TRUE;
|
||||
if ($EndpointConnections.Count -eq 0) {
|
||||
|
|
@ -556,7 +556,7 @@ function Start-IcingaAgentInstallWizard()
|
|||
|
||||
if ($null -eq $GlobalZones) {
|
||||
if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Do you want to add custom global zones?' -Default 'n').result -eq 0) {
|
||||
$ArrayString = (Get-IcingaAgentInstallerAnswerInput -Prompt 'Please specify your additional zones seperated by "," (Example: "global-zone1, global-zone2")' -Default 'v').answer;
|
||||
$ArrayString = (Get-IcingaAgentInstallerAnswerInput -Prompt 'Please specify your additional zones separated by "," (Example: "global-zone1, global-zone2")' -Default 'v').answer;
|
||||
if ([string]::IsNullOrEmpty($ArrayString) -eq $FALSE) {
|
||||
$GlobalZones = ($ArrayString.Replace(' ', '')).Split(',')
|
||||
$GlobalZoneConfig += $GlobalZones;
|
||||
|
|
@ -722,7 +722,7 @@ function Start-IcingaAgentInstallWizard()
|
|||
Reset-IcingaAgentConfigFile;
|
||||
Move-IcingaAgentDefaultConfig;
|
||||
Set-IcingaAgentNodeName -Hostname $Hostname;
|
||||
Set-IcingaAgentServiceUser -User $ServiceUser -Password $ServicePass -SetPermission | Out-Null;
|
||||
Set-IcingaServiceUser -User $ServiceUser -Password $ServicePass -SetPermission | Out-Null;
|
||||
if ($InstallFrameworkService) {
|
||||
Install-IcingaForWindowsService -Path $ServiceBin -User $ServiceUser -Password $ServicePass | Out-Null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ function Test-IcingaAgent()
|
|||
Test-IcingaAcl "$Env:ProgramData\icinga2\var" -WriteOutput | Out-Null;
|
||||
Test-IcingaAcl (Get-IcingaCacheDir) -WriteOutput | Out-Null;
|
||||
Test-IcingaAcl (Get-IcingaPowerShellConfigDir) -WriteOutput | Out-Null;
|
||||
Test-IcingaAcl -Directory (Join-Path -Path (Get-IcingaFrameworkRootPath) -ChildPath 'certificate') -WriteOutput | Out-Null;;
|
||||
Test-IcingaAcl -Directory (Join-Path -Path (Get-IcingaFrameworkRootPath) -ChildPath 'certificate') -WriteOutput | Out-Null;
|
||||
|
||||
if ($IcingaAgentData.Installed) {
|
||||
Test-IcingaAgentConfig | Out-Null;
|
||||
|
|
|
|||
|
|
@ -183,7 +183,7 @@ function Start-IcingaForWindowsInstallation()
|
|||
Reset-IcingaAgentConfigFile;
|
||||
Move-IcingaAgentDefaultConfig;
|
||||
Set-IcingaAgentNodeName -Hostname $Hostname;
|
||||
Set-IcingaAgentServiceUser -User $ServiceUser -Password (ConvertTo-IcingaSecureString $ServicePassword) -SetPermission | Out-Null;
|
||||
Set-IcingaServiceUser -User $ServiceUser -Password (ConvertTo-IcingaSecureString $ServicePassword) -SetPermission | Out-Null;
|
||||
Install-IcingaAgentBaseFeatures;
|
||||
Write-IcingaAgentApiConfig -Port $IcingaPort;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ function Show-IcingaForWindowsManagementConsoleManageFramework()
|
|||
'Help' = 'In case enabled, all check commands executed by "Exit-IcingaExecutePlugin" are forwarded to an internal REST-Api and executed from within the Icinga for Windows background daemon. Requires the Icinga for Windows background daemon';
|
||||
'Disabled' = $FALSE;
|
||||
'Action' = @{
|
||||
'Command' = 'Invoke-IcingaForWindowsMangementConsoleToogleFrameworkApiChecks';
|
||||
'Command' = 'Invoke-IcingaForWindowsManagementConsoleToggleFrameworkApiChecks';
|
||||
'Arguments' = @{ };
|
||||
}
|
||||
},
|
||||
|
|
@ -53,7 +53,7 @@ function Show-IcingaForWindowsManagementConsoleManageFramework()
|
|||
'Help' = 'Disable or enable the Icinga PowerShell Framework debug mode';
|
||||
'Disabled' = $FALSE;
|
||||
'Action' = @{
|
||||
'Command' = 'Invoke-IcingaForWindowsMangementConsoleToogleFrameworkDebug';
|
||||
'Command' = 'Invoke-IcingaForWindowsManagementConsoleToggleFrameworkDebug';
|
||||
}
|
||||
},
|
||||
@{
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
function Invoke-IcingaForWindowsMangementConsoleToogleFrameworkApiChecks()
|
||||
function Invoke-IcingaForWindowsManagementConsoleToggleFrameworkApiChecks()
|
||||
{
|
||||
if (Get-IcingaFrameworkApiChecks) {
|
||||
Disable-IcingaFrameworkApiChecks;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
function Invoke-IcingaForWindowsMangementConsoleToogleFrameworkDebug()
|
||||
function Invoke-IcingaForWindowsManagementConsoleToggleFrameworkDebug()
|
||||
{
|
||||
if (Get-IcingaFrameworkDebugMode) {
|
||||
Disable-IcingaFrameworkDebugMode;
|
||||
|
|
|
|||
|
|
@ -8,11 +8,13 @@
|
|||
.EXAMPLE
|
||||
PS>Write-IcingaConsoleError -Message 'Test message: {0}' -Objects 'Hello World';
|
||||
.PARAMETER Message
|
||||
The message to print with {x} placeholdes replaced by content inside the Objects array. Replace x with the
|
||||
The message to print with {x} placeholder replaced by content inside the Objects array. Replace x with the
|
||||
number of the index from the objects array
|
||||
.PARAMETER Objects
|
||||
An array of objects being added to a provided message. The index of the array position has to refer to the
|
||||
message locations.
|
||||
.PARAMETER DropMessage
|
||||
Allows to programmatically drop a message in case it is not required without dealing with If-Blocks
|
||||
.INPUTS
|
||||
System.String
|
||||
.LINK
|
||||
|
|
|
|||
|
|
@ -2,15 +2,15 @@
|
|||
.SYNOPSIS
|
||||
Creates counter objects and sub-instances from a given Performance Counter
|
||||
Will return either a New-IcingaPerformanceCounterObject or New-IcingaPerformanceCounterResult
|
||||
which both contain the same members, allowing for dynmically use of objects
|
||||
which both contain the same members, allowing for dynamically use of objects
|
||||
.DESCRIPTION
|
||||
Creates counter objects and sub-instances from a given Performance Counter
|
||||
Will return either a New-IcingaPerformanceCounterObject or New-IcingaPerformanceCounterResult
|
||||
which both contain the same members, allowing for dynmically use of objects
|
||||
which both contain the same members, allowing for dynamically use of objects
|
||||
.FUNCTIONALITY
|
||||
Creates counter objects and sub-instances from a given Performance Counter
|
||||
Will return either a New-IcingaPerformanceCounterObject or New-IcingaPerformanceCounterResult
|
||||
which both contain the same members, allowing for dynmically use of objects
|
||||
which both contain the same members, allowing for dynamically use of objects
|
||||
.EXAMPLE
|
||||
PS>New-IcingaPerformanceCounter -Counter '\Processor(*)\% processor time';
|
||||
|
||||
|
|
@ -72,10 +72,10 @@ function New-IcingaPerformanceCounter()
|
|||
# At last get the actual counter containing our values
|
||||
$UseCounterName = $CounterArray[2];
|
||||
|
||||
# Now as we know how the counter path is constructed and has been splitted into
|
||||
# Now as we know how the counter path is constructed and has been split into
|
||||
# the different values, we need to know how to handle the instances of the counter
|
||||
|
||||
# If we specify a instance with (*) we want the module to automaticly fetch all
|
||||
# If we specify a instance with (*) we want the module to automatically fetch all
|
||||
# instances for this counter. This will result in an New-IcingaPerformanceCounterResult
|
||||
# which contains the parent name including counters for all instances that
|
||||
# have been found
|
||||
|
|
@ -91,12 +91,12 @@ function New-IcingaPerformanceCounter()
|
|||
# create single performance counters and add them to a custom array and
|
||||
# later to a custom object
|
||||
try {
|
||||
[array]$AllCountersIntances = @();
|
||||
[array]$AllCountersInstances = @();
|
||||
$CounterInstances = New-Object System.Diagnostics.PerformanceCounterCategory($UseCounterCategory);
|
||||
foreach ($instance in $CounterInstances.GetInstanceNames()) {
|
||||
[string]$NewCounterName = $Counter.Replace('*', $instance);
|
||||
$NewCounter = New-IcingaPerformanceCounterObject -FullName $NewCounterName -Category $UseCounterCategory -Counter $UseCounterName -Instance $instance -SkipWait $TRUE;
|
||||
$AllCountersIntances += $NewCounter;
|
||||
$AllCountersInstances += $NewCounter;
|
||||
}
|
||||
} catch {
|
||||
# Throw an exception in case our permissions are not enough to fetch performance counter
|
||||
|
|
@ -108,7 +108,7 @@ function New-IcingaPerformanceCounter()
|
|||
}
|
||||
|
||||
# If we load multiple instances, we should add a global wait here instead of a wait for each single instance
|
||||
# This will speed up CPU loading for example with plenty of cores avaiable
|
||||
# This will speed up CPU loading for example with plenty of cores available
|
||||
if ($SkipWait -eq $FALSE) {
|
||||
Start-Sleep -Milliseconds 500;
|
||||
}
|
||||
|
|
@ -116,11 +116,11 @@ function New-IcingaPerformanceCounter()
|
|||
# Add the parent counter including the array of Performance Counters to our
|
||||
# caching mechanism and return the New-IcingaPerformanceCounterResult object for usage
|
||||
# within the monitoring modules
|
||||
Add-IcingaPerformanceCounterCache -Counter $Counter -Instances $AllCountersIntances;
|
||||
return (New-IcingaPerformanceCounterResult -FullName $Counter -PerformanceCounters $AllCountersIntances);
|
||||
Add-IcingaPerformanceCounterCache -Counter $Counter -Instances $AllCountersInstances;
|
||||
return (New-IcingaPerformanceCounterResult -FullName $Counter -PerformanceCounters $AllCountersInstances);
|
||||
} else {
|
||||
# This part will handle the counters without any instances as well as
|
||||
# specificly assigned instances, like (_Total) CPU usage.
|
||||
# specifically assigned instances, like (_Total) CPU usage.
|
||||
|
||||
# In case we already have the counter within our cache, return the
|
||||
# cached informations
|
||||
|
|
@ -137,7 +137,7 @@ function New-IcingaPerformanceCounter()
|
|||
}
|
||||
|
||||
# This function will always return non-instance counters or
|
||||
# specificly defined instance counters. Performance Counter Arrays
|
||||
# specifically defined instance counters. Performance Counter Arrays
|
||||
# are returned within their function. This is just to ensure that the
|
||||
# function looks finished from developer point of view
|
||||
return (Get-IcingaPerformanceCounterCacheItem -Counter $Counter);
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ function New-IcingaPerformanceCounterArray()
|
|||
[array]$CounterArray = @()
|
||||
)
|
||||
|
||||
[hashtable]$CounterResult = @{};
|
||||
[hashtable]$CounterResult = @{ };
|
||||
[bool]$RequireSleep = $TRUE;
|
||||
foreach ($counter in $CounterArray) {
|
||||
# We want to speed up things with loading, so we will check if a specified
|
||||
|
|
@ -59,14 +59,14 @@ function New-IcingaPerformanceCounterArray()
|
|||
# Internally we could do something like this
|
||||
# $global:Icinga_PerfCounterCache += $CounterResult;
|
||||
|
||||
# Above we initialse ever single counter and we only require a sleep once
|
||||
# Above we initialise ever single counter and we only require a sleep once
|
||||
# in case a new, yet unknown counter was added
|
||||
if ($RequireSleep) {
|
||||
Start-Sleep -Milliseconds 500;
|
||||
|
||||
# Agreed, this is some sort of code duplication but it wouldn't make
|
||||
# any sense to create a own function for this. Why are we doing
|
||||
# this anway?
|
||||
# this anyway?
|
||||
# Simple: In case we found counters which have yet not been initialised
|
||||
# we did this above. Now we have waited 500 ms to receive proper
|
||||
# values from these counters. As the previous generated result
|
||||
|
|
@ -76,9 +76,9 @@ function New-IcingaPerformanceCounterArray()
|
|||
# applies to the first call of the module with the counters.
|
||||
# This 'duplication' however decreased the execution from
|
||||
# certain modules from 25s to 1s on the first run. Every
|
||||
# additional run is then beeing executed within 0.x s
|
||||
# additional run is then being executed within 0.x s
|
||||
# which sounds like a very good performance and solution
|
||||
$CounterResult = @{};
|
||||
$CounterResult = @{ };
|
||||
foreach ($counter in $CounterArray) {
|
||||
$obj = New-IcingaPerformanceCounter -Counter $counter -SkipWait $TRUE;
|
||||
if ($CounterResult.ContainsKey($obj.Name()) -eq $FALSE) {
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ function New-IcingaPerformanceCounterCache()
|
|||
if ($null -eq $global:Icinga_PerfCounterCache) {
|
||||
$global:Icinga_PerfCounterCache = (
|
||||
[hashtable]::Synchronized(
|
||||
@{}
|
||||
@{ }
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
This will create a Performance Counter object in case a counter instance
|
||||
does not exis, but still returning default members to allow us to smoothly
|
||||
does not exist, but still returning default members to allow us to smoothly
|
||||
execute our code
|
||||
.DESCRIPTION
|
||||
This will create a Performance Counter object in case a counter instance
|
||||
does not exis, but still returning default members to allow us to smoothly
|
||||
does not exist, but still returning default members to allow us to smoothly
|
||||
execute our code
|
||||
.FUNCTIONALITY
|
||||
This will create a Performance Counter object in case a counter instance
|
||||
does not exis, but still returning default members to allow us to smoothly
|
||||
does not exist, but still returning default members to allow us to smoothly
|
||||
execute our code
|
||||
.EXAMPLE
|
||||
PS>New-IcingaPerformanceCounterNullObject '\Processor(20)\%processor time' -ErrorMessage 'This counter with instance 20 does not exist';
|
||||
|
|
@ -45,7 +45,7 @@ function New-IcingaPerformanceCounterNullObject()
|
|||
}
|
||||
|
||||
$pc_instance | Add-Member -MemberType ScriptMethod -Name 'Value' -Value {
|
||||
[hashtable]$ErrorMessage = @{};
|
||||
[hashtable]$ErrorMessage = @{ };
|
||||
|
||||
$ErrorMessage.Add('value', $null);
|
||||
$ErrorMessage.Add('sample', $null);
|
||||
|
|
|
|||
|
|
@ -103,12 +103,12 @@ function New-IcingaPerformanceCounterObject()
|
|||
}
|
||||
|
||||
<#
|
||||
# Return a hashtable containting the counter value including the
|
||||
# Return a hashtable containing the counter value including the
|
||||
# Sample values for the counter itself. In case we run into an error,
|
||||
# keep the counter construct but add an error message in addition.
|
||||
#>
|
||||
$pc_instance | Add-Member -MemberType ScriptMethod -Name 'Value' -Value {
|
||||
[hashtable]$CounterData = @{};
|
||||
[hashtable]$CounterData = @{ };
|
||||
|
||||
try {
|
||||
[string]$CounterType = $this.PerfCounter.CounterType;
|
||||
|
|
@ -118,7 +118,7 @@ function New-IcingaPerformanceCounterObject()
|
|||
$CounterData.Add('type', $CounterType);
|
||||
$CounterData.Add('error', $null);
|
||||
} catch {
|
||||
$CounterData = @{};
|
||||
$CounterData = @{ };
|
||||
$CounterData.Add('value', $null);
|
||||
$CounterData.Add('sample', $null);
|
||||
$CounterData.Add('help', $null);
|
||||
|
|
@ -129,7 +129,7 @@ function New-IcingaPerformanceCounterObject()
|
|||
return $CounterData;
|
||||
}
|
||||
|
||||
# Initialiste the entire counter and internal handlers
|
||||
# Initialise the entire counter and internal handlers
|
||||
$pc_instance.Init();
|
||||
|
||||
# Return this custom object
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ function New-IcingaPerformanceCounterResult()
|
|||
}
|
||||
|
||||
$pc_instance | Add-Member -MemberType ScriptMethod -Name 'Value' -Value {
|
||||
[hashtable]$CounterResults = @{};
|
||||
[hashtable]$CounterResults = @{ };
|
||||
|
||||
foreach ($counter in $this.Counters) {
|
||||
$CounterResults.Add($counter.Name(), $counter.Value());
|
||||
|
|
|
|||
|
|
@ -3,17 +3,17 @@
|
|||
Will use an array of provided Performance Counter and sort the input by
|
||||
a given counter category. In this case we can fetch all Processor instances
|
||||
and receive values for each core which can then be accessed from a hashtable
|
||||
with an eady query. Allows to modify output in addition
|
||||
with an ready query. Allows to modify output in addition
|
||||
.DESCRIPTION
|
||||
Will use an array of provided Performance Counter and sort the input by
|
||||
a given counter category. In this case we can fetch all Processor instances
|
||||
and receive values for each core which can then be accessed from a hashtable
|
||||
with an eady query. Allows to modify output in addition
|
||||
with an ready query. Allows to modify output in addition
|
||||
.FUNCTIONALITY
|
||||
Will use an array of provided Performance Counter and sort the input by
|
||||
a given counter category. In this case we can fetch all Processor instances
|
||||
and receive values for each core which can then be accessed from a hashtable
|
||||
with an eady query. Allows to modify output in addition
|
||||
with an ready query. Allows to modify output in addition
|
||||
.EXAMPLE
|
||||
PS>New-IcingaPerformanceCounterStructure -CounterCategory 'Processor' -PerformanceCounterHash (New-IcingaPerformanceCounterArray '\Processor(*)\% processor time');
|
||||
|
||||
|
|
@ -60,13 +60,13 @@ function New-IcingaPerformanceCounterStructure()
|
|||
{
|
||||
param(
|
||||
[string]$CounterCategory = '',
|
||||
[hashtable]$PerformanceCounterHash = @{},
|
||||
[hashtable]$PerformanceCounterHash = @{ },
|
||||
[array]$InstanceNameCleanupArray = @()
|
||||
)
|
||||
|
||||
# The storage variables we require to store our data
|
||||
[array]$AvailableInstances = @();
|
||||
[hashtable]$StructuredCounterData = @{};
|
||||
[hashtable]$StructuredCounterData = @{ };
|
||||
|
||||
# With this little trick we can fetch all instances we have and get their unique name
|
||||
$CounterInstances = New-Object System.Diagnostics.PerformanceCounterCategory($CounterCategory);
|
||||
|
|
@ -93,7 +93,7 @@ function New-IcingaPerformanceCounterStructure()
|
|||
foreach ($instance in $AvailableInstances) {
|
||||
|
||||
# First build a hashtable for each instance to add data to later
|
||||
$StructuredCounterData.Add($instance, @{});
|
||||
$StructuredCounterData.Add($instance, @{ });
|
||||
|
||||
# Now we need to loop all return values from our Performance Counters
|
||||
foreach ($InterfaceCounter in $PerformanceCounterHash.Keys) {
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ function Show-IcingaPerformanceCounterHelp()
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ([string]::IsNullOrEmpty($HelpText) -eq $FALSE) {
|
||||
return $HelpText;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ function Show-IcingaPerformanceCounterInstances()
|
|||
[string]$Counter
|
||||
);
|
||||
|
||||
[hashtable]$Instances = @{};
|
||||
[hashtable]$Instances = @{ };
|
||||
|
||||
if ([string]::IsNullOrEmpty($Counter)) {
|
||||
Write-IcingaConsoleError 'Please enter a Performance Counter';
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
\Processor(*)\% dpc time
|
||||
\Processor(*)\% privileged time
|
||||
.PARAMETER CounterCategory
|
||||
The name of the category to fetch availble counters for
|
||||
The name of the category to fetch available counters for
|
||||
.INPUTS
|
||||
System.String
|
||||
.OUTPUTS
|
||||
|
|
@ -30,7 +30,7 @@ function Show-IcingaPerformanceCounters()
|
|||
[string]$CounterCategory
|
||||
);
|
||||
|
||||
[hashtable]$counters = @{};
|
||||
[hashtable]$counters = @{ };
|
||||
|
||||
if ([string]::IsNullOrEmpty($CounterCategory)) {
|
||||
$counters.Add('error', 'Please specify a counter category');
|
||||
|
|
|
|||
|
|
@ -367,7 +367,7 @@ function Install-IcingaComponent()
|
|||
return $FALSE;
|
||||
}
|
||||
|
||||
Set-IcingaAgentServiceUser -User $ServiceUser -SetPermission;
|
||||
Set-IcingaServiceUser -User $ServiceUser -SetPermission;
|
||||
Update-IcingaServiceUser;
|
||||
|
||||
Write-IcingaConsoleNotice 'Installation of component "agent" with version "{0}" was successful.' -Objects $MSIData.ProductVersion;
|
||||
|
|
|
|||
|
|
@ -147,7 +147,7 @@ function Sync-IcingaRepository()
|
|||
|
||||
try {
|
||||
Write-IcingaConsoleNotice 'Syncing repository component "{0}" as file "{1}" into temp directory' -Objects $component, $package.Location;
|
||||
Invoke-IcingaWebRequest -USeBasicParsing -Uri $DownloadLink -OutFile $TargetLocation | Out-Null;
|
||||
Invoke-IcingaWebRequest -UseBasicParsing -Uri $DownloadLink -OutFile $TargetLocation | Out-Null;
|
||||
} catch {
|
||||
Write-IcingaConsoleError 'Failed to download repository component "{0}". Exception: "{1}"' -Objects $DownloadLink, $_.Exception.Message;
|
||||
continue;
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ function Get-IcingaNetworkInterface()
|
|||
|
||||
$IPBinStringMaster = ConvertTo-IcingaIPBinaryString -IP $IP;
|
||||
|
||||
[hashtable]$InterfaceData=@{};
|
||||
[hashtable]$InterfaceData = @{ };
|
||||
|
||||
$InterfaceInfo = Get-NetRoute;
|
||||
$Counter = 0;
|
||||
|
|
@ -106,7 +106,7 @@ function Get-IcingaNetworkInterface()
|
|||
}
|
||||
|
||||
$InterfaceDataOrdered = $InterfaceData.GetEnumerator() | Sort-Object -Property Name -Descending;
|
||||
$ExternalInterfaces = @{};
|
||||
$ExternalInterfaces = @{ };
|
||||
|
||||
foreach ( $Route in $InterfaceDataOrdered ) {
|
||||
foreach ($destinationIP in $IPBinStringMaster) {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ function Get-IcingaPSObjectProperties()
|
|||
[array]$Exclude = @()
|
||||
);
|
||||
|
||||
[hashtable]$RetValue = @{};
|
||||
[hashtable]$RetValue = @{ };
|
||||
|
||||
if ($null -eq $Object) {
|
||||
return $RetValue;
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ function New-IcingaBasicAuthHeader()
|
|||
|
||||
if ($null -eq $Password -or [string]::IsNullOrEmpty($Username)) {
|
||||
Write-IcingaConsoleWarning 'Please specify your username and password to continue';
|
||||
return @{};
|
||||
return @{ };
|
||||
}
|
||||
|
||||
$Credentials = [System.Convert]::ToBase64String(
|
||||
|
|
|
|||
|
|
@ -2,12 +2,12 @@
|
|||
.SYNOPSIS
|
||||
Tests for binary operators with -band if a specific Value contains binary
|
||||
operators within a Compare array. In addition you can use a Namespace
|
||||
argument to provide a hashtable in which your key values are included to
|
||||
argument to provide a hashtable in which your key values are included to
|
||||
reduce the amount of code to write
|
||||
.DESCRIPTION
|
||||
Tests for binary operators with -band if a specific Value contains binary
|
||||
operators within a Compare array. In addition you can use a Namespace
|
||||
argument to provide a hashtable in which your key values are included to
|
||||
argument to provide a hashtable in which your key values are included to
|
||||
reduce the amount of code to write
|
||||
.EXAMPLE
|
||||
PS>Test-IcingaBinaryOperator -Value Ok -Compare EmptyClass, InvalidNameSpace, PermissionError, Ok -Namespace $TestIcingaWindowsInfoEnums.TestIcingaWindowsInfo;
|
||||
|
|
@ -20,7 +20,7 @@
|
|||
the name of the key for a Namespace or a numeric value
|
||||
.PARAMETER Compare
|
||||
An array of values to compare for and check if the value matches with the -band operator
|
||||
The array can either contain the key names of your Namespace, numeric values or both cominbed
|
||||
The array can either contain the key names of your Namespace, numeric values or both combined
|
||||
.PARAMETER Namespace
|
||||
A hashtable object containing values you want to compare for. By providing a hashtable here
|
||||
you can use the key names for each value on the Value and Compare argument
|
||||
|
|
@ -62,7 +62,7 @@ function Test-IcingaBinaryOperator()
|
|||
if (($Namespace[$Value] -band $BinaryValue) -eq $Namespace[$Value]) {
|
||||
return $TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $FALSE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ function Get-IcingaBackgroundDaemons()
|
|||
return $null;
|
||||
}
|
||||
|
||||
[hashtable]$Output = @{};
|
||||
[hashtable]$Output = @{ };
|
||||
|
||||
foreach ($daemon in $Daemons.PSObject.Properties) {
|
||||
$Arguments = @{ };
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
function Invoke-IcingaRESTAPIv1Calls()
|
||||
{
|
||||
param (
|
||||
[Hashtable]$Request = @{},
|
||||
[Hashtable]$Connection = @{}
|
||||
[Hashtable]$Request = @{ },
|
||||
[Hashtable]$Connection = @{ }
|
||||
);
|
||||
|
||||
[string]$ModuleToLoad = Get-IcingaRESTPathElement -Request $Request -Index 1;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
function Test-IcingaRESTClientConnection()
|
||||
{
|
||||
param(
|
||||
[Hashtable]$Connection = @{}
|
||||
[Hashtable]$Connection = @{ }
|
||||
);
|
||||
|
||||
# If we couldn't establish a proper SSL stream, close the connection
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ function New-IcingaForWindowsRESTApi()
|
|||
# allow to share data collected from this daemon with others
|
||||
$IcingaDaemonData.BackgroundDaemon.Add(
|
||||
'IcingaPowerShellRestApi',
|
||||
[hashtable]::Synchronized(@{})
|
||||
[hashtable]::Synchronized(@{ })
|
||||
);
|
||||
|
||||
# Map our Icinga globals to a shorter variable
|
||||
|
|
@ -33,7 +33,7 @@ function New-IcingaForWindowsRESTApi()
|
|||
# endpoint configurations for the API
|
||||
$RestDaemon.Add(
|
||||
'RegisteredEndpoints',
|
||||
[hashtable]::Synchronized(@{})
|
||||
[hashtable]::Synchronized(@{ })
|
||||
);
|
||||
|
||||
# This will add another hashtable to our previous
|
||||
|
|
@ -41,7 +41,7 @@ function New-IcingaForWindowsRESTApi()
|
|||
# command aliases for execution for the API
|
||||
$RestDaemon.Add(
|
||||
'CommandAliases',
|
||||
[hashtable]::Synchronized(@{})
|
||||
[hashtable]::Synchronized(@{ })
|
||||
);
|
||||
|
||||
# This will add another hashtable to our previous
|
||||
|
|
@ -49,7 +49,7 @@ function New-IcingaForWindowsRESTApi()
|
|||
# command aliases for execution for the API
|
||||
$RestDaemon.Add(
|
||||
'ClientBlacklist',
|
||||
[hashtable]::Synchronized(@{})
|
||||
[hashtable]::Synchronized(@{ })
|
||||
);
|
||||
|
||||
# Make the root folder of our rest daemon module available
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
function Get-IcingaRegisteredServiceChecks()
|
||||
{
|
||||
$Services = Get-IcingaPowerShellConfig -Path 'BackgroundDaemon.RegisteredServices';
|
||||
[hashtable]$Output = @{};
|
||||
[hashtable]$Output = @{ };
|
||||
|
||||
foreach ($service in $Services.PSObject.Properties) {
|
||||
$Content = @{
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ function Convert-Base64ToCredentials()
|
|||
[String]$AuthString
|
||||
);
|
||||
|
||||
[hashtable]$Credentials = @{};
|
||||
[hashtable]$Credentials = @{ };
|
||||
|
||||
$AuthArray = $AuthString.Split(' ');
|
||||
|
||||
|
|
@ -33,7 +33,7 @@ function Convert-Base64ToCredentials()
|
|||
};
|
||||
default {
|
||||
Write-IcingaEventMessage -EventId 1550 -Namespace 'Framework' -Objects $AuthArray[0];
|
||||
return @{};
|
||||
return @{ };
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -44,7 +44,7 @@ function Convert-Base64ToCredentials()
|
|||
)
|
||||
);
|
||||
|
||||
# If no ':' is within the string, the credential data is not properly formated
|
||||
# If no ':' is within the string, the credential data is not properly formatted
|
||||
if ($AuthString.Contains(':') -eq $FALSE) {
|
||||
Write-IcingaEventMessage -EventId 1551 -Namespace 'Framework';
|
||||
$AuthString = $null;
|
||||
|
|
@ -93,7 +93,7 @@ function Convert-Base64ToCredentials()
|
|||
$UserData = $null;
|
||||
} catch {
|
||||
Write-IcingaEventMessage -EventId 1552 -Namespace 'Framework' -Objects $_.Exception;
|
||||
return @{};
|
||||
return @{ };
|
||||
}
|
||||
|
||||
return $Credentials;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
function Get-IcingaRESTHeaderValue()
|
||||
{
|
||||
param(
|
||||
[hashtable]$Request = @{},
|
||||
[hashtable]$Request = @{ },
|
||||
[string]$Header = $null
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
function Get-IcingaRESTPathElement()
|
||||
{
|
||||
param(
|
||||
[Hashtable]$Request = @{},
|
||||
[Hashtable]$Request = @{ },
|
||||
[int]$Index = 0
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ function Read-IcingaRESTMessage()
|
|||
[hashtable]$Connection = $null
|
||||
);
|
||||
|
||||
# Just in case we didnt receive anything - no need to
|
||||
# Just in case we didn't receive anything - no need to
|
||||
# parse through everything
|
||||
if ([string]::IsNullOrEmpty($RestMessage)) {
|
||||
return $null;
|
||||
|
|
@ -14,18 +14,18 @@ function Read-IcingaRESTMessage()
|
|||
Write-IcingaDebugMessage (
|
||||
[string]::Format(
|
||||
'Receiving client message{0}{0}{1}',
|
||||
(New-IcingaNewline),
|
||||
(New-IcingaNewLine),
|
||||
$RestMessage
|
||||
)
|
||||
);
|
||||
|
||||
[hashtable]$Request = @{};
|
||||
[hashtable]$Request = @{ };
|
||||
$RestMessage -match '(.+) (.+) (.+)' | Out-Null;
|
||||
|
||||
$Request.Add('Method', $Matches[1]);
|
||||
$Request.Add('FullRequest', $Matches[2]);
|
||||
$Request.Add('RequestPath', @{});
|
||||
$Request.Add('RequestArguments', @{});
|
||||
$Request.Add('RequestPath', @{ });
|
||||
$Request.Add('RequestArguments', @{ });
|
||||
|
||||
#Path
|
||||
$PathMatch = $Matches[2];
|
||||
|
|
@ -75,7 +75,7 @@ function Read-IcingaRESTMessage()
|
|||
$Request.Add('Body', $Matches[1]);
|
||||
}
|
||||
|
||||
# We received a content length, but couldnt load the body. Some clients will send the body as separate message
|
||||
# We received a content length, but couldn't load the body. Some clients will send the body as separate message
|
||||
# Lets try to read the body content
|
||||
if ($null -ne $Connection) {
|
||||
if ($Request.ContainsKey('ContentLength') -And $Request.ContentLength -gt 0 -And ($Request.ContainsKey('Body') -eq $FALSE -Or [string]::IsNullOrEmpty($Request.Body))) {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
function Read-IcingaTCPStream()
|
||||
{
|
||||
param(
|
||||
[System.Net.Sockets.TcpClient]$Client = @{},
|
||||
[System.Net.Sockets.TcpClient]$Client = @{ },
|
||||
[System.Net.Security.SslStream]$Stream = $null,
|
||||
[int]$ReadLength = 0
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
function Send-IcingaTCPClientMessage()
|
||||
{
|
||||
param(
|
||||
[Hashtable]$Message = @{},
|
||||
[Hashtable]$Message = @{ },
|
||||
[System.Net.Security.SslStream]$Stream = $null
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
function Send-IcingaWebAuthMessage()
|
||||
{
|
||||
param (
|
||||
[Hashtable]$Connection = @{}
|
||||
[Hashtable]$Connection = @{ }
|
||||
);
|
||||
|
||||
Send-IcingaTCPClientMessage -Message (
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@
|
|||
# WMI WBEM_SECURITY_FLAGS
|
||||
# https://docs.microsoft.com/en-us/windows/win32/api/wbemcli/ne-wbemcli-wbem_security_flags
|
||||
# https://docs.microsoft.com/en-us/windows/win32/secauthz/standard-access-rights
|
||||
#>
|
||||
|
||||
[hashtable]$SecurityFlags = @{
|
||||
#>
|
||||
|
||||
[hashtable]$SecurityFlags = @{
|
||||
'WBEM_Enable' = 1;
|
||||
'WBEM_Method_Execute' = 2;
|
||||
'WBEM_Full_Write_Rep' = 4;
|
||||
|
|
|
|||
|
|
@ -18,9 +18,9 @@
|
|||
.PARAMETER Recurse
|
||||
Applies a container inherit flag and grants permission not only on the specific Wmi tree but also objects within this namespace (recommended)
|
||||
.PARAMETER DenyAccess
|
||||
Blocks the user from having access to this Wmi and or subnamespace tree.
|
||||
Blocks the user from having access to this Wmi and or sub namespace tree.
|
||||
.PARAMETER Flags
|
||||
Allows to specify additional flags for permssion granting: PartialWrite, Subscribe, ProviderWrite,ReadSecurity, WriteSecurity, Publish, MethodExecute, FullWrite
|
||||
Allows to specify additional flags for permission granting: PartialWrite, Subscribe, ProviderWrite,ReadSecurity, WriteSecurity, Publish, MethodExecute, FullWrite
|
||||
.INPUTS
|
||||
System.String
|
||||
.OUTPUTS
|
||||
|
|
@ -87,6 +87,6 @@ function Test-IcingaWmiPermissions()
|
|||
if ($UserACL.AccessMask -ne $PermissionMask -Or $RecurseMatch -eq $FALSE) {
|
||||
return $FALSE;
|
||||
}
|
||||
|
||||
|
||||
return $TRUE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,8 @@
|
|||
ExcludeRules = @(
|
||||
'PSAvoidGlobalVars',
|
||||
'PSUseSingularNouns',
|
||||
'PSAvoidUsingWriteHost'
|
||||
'PSAvoidUsingWriteHost',
|
||||
'PSUseToExportFieldsInManifest'
|
||||
)
|
||||
Rules = @{
|
||||
PSUseCompatibleCmdlets = @{
|
||||
|
|
@ -44,11 +45,13 @@
|
|||
IgnoreOneLineBlock = $true
|
||||
NoEmptyLineBefore = $true
|
||||
};
|
||||
# Disabled for the moment, as the indentation handling is not properly
|
||||
# handling multi-line arrays and hashtables
|
||||
PSUseConsistentIndentation = @{
|
||||
Enable = $true
|
||||
Enable = $false
|
||||
Kind = 'space'
|
||||
IndentationSize = 4
|
||||
PipelineIndentation = 'IncreaseIndentationForFirstPipeline'
|
||||
PipelineIndentation = 'IncreaseIndentationAfterEveryPipeline'
|
||||
};
|
||||
PSUseConsistentWhitespace = @{
|
||||
Enable = $true
|
||||
|
|
|
|||
Loading…
Reference in a new issue