mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-20 23:00:35 -05:00
Merge branch 'master' into support/1.0
This commit is contained in:
commit
8d9cf07ee1
32 changed files with 1020 additions and 217 deletions
5
.gitattributes
vendored
Normal file
5
.gitattributes
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
# Exclude files related to git when generating an archive
|
||||||
|
.git* export-ignore
|
||||||
|
|
||||||
|
# Include version information on `git archive'
|
||||||
|
VERSION export-subst
|
||||||
|
|
@ -13,12 +13,13 @@ Please take a look at the following content to get to know the possibilities of
|
||||||
|
|
||||||
* [Introduction](doc/01-Introduction.md)
|
* [Introduction](doc/01-Introduction.md)
|
||||||
* [Installation Guide](doc/02-Installation.md)
|
* [Installation Guide](doc/02-Installation.md)
|
||||||
* [Icinga Integration](doc/05-IcingaIntegration.md)
|
* [Icinga Integration](doc/05-Icinga-Integration.md)
|
||||||
|
* [PowerShell as Service](doc/service/01-Install-Service.md)
|
||||||
|
|
||||||
Developer Guide
|
Developer Guide
|
||||||
------------
|
------------
|
||||||
|
|
||||||
If you wish to extend the Framework by yourself or write custom plugins for your environment, please have a look at the [Developer Guide](doc/04-DeveloperGuide.md) for detailed explanations of functions and code examples.
|
If you wish to extend the Framework by yourself or write custom plugins for your environment, please have a look at the [Developer Guide](doc/04-Developer-Guide.md) for detailed explanations of functions and code examples.
|
||||||
|
|
||||||
Contributing
|
Contributing
|
||||||
------------
|
------------
|
||||||
|
|
|
||||||
|
|
@ -21,3 +21,10 @@ Use-Icinga
|
||||||
This command will initialise the entire module and load all available Cmdlets.
|
This command will initialise the entire module and load all available Cmdlets.
|
||||||
|
|
||||||
Whenever you intend to use specific Cmdlets of the framework for Icinga Plugins, Testing or configuration you will require to run this command for each new PowerShell instance to initialise the framework.
|
Whenever you intend to use specific Cmdlets of the framework for Icinga Plugins, Testing or configuration you will require to run this command for each new PowerShell instance to initialise the framework.
|
||||||
|
|
||||||
|
Service Installation
|
||||||
|
---
|
||||||
|
|
||||||
|
You can install a service which will allow you to run the PowerShell Framework as background daemon. This will add the possibility to register functions to run frequently for collecting data or execute different tasks on the system.
|
||||||
|
|
||||||
|
To install the service you can either follow the `IcingaAgentInstallWizard` or do it [manually](service/01-Install-Service.md)
|
||||||
|
|
|
||||||
|
|
@ -12,3 +12,4 @@ A detailed overview of functions can be found below
|
||||||
|
|
||||||
* [New-IcingaCheck](developerguide/01-New-IcingaCheck.md)
|
* [New-IcingaCheck](developerguide/01-New-IcingaCheck.md)
|
||||||
* [New-IcingaCheckPackage](developerguide/02-New-IcingaCheckPackage.md)
|
* [New-IcingaCheckPackage](developerguide/02-New-IcingaCheckPackage.md)
|
||||||
|
* [Custom Daemons](developerguide/10-Custom-Daemons.md)
|
||||||
|
|
|
||||||
|
|
@ -42,10 +42,10 @@ For performance metrics you can provide a `Unit` to ensure your graphing is disp
|
||||||
| ms | Milliseconds | The input is indicated as time in milliseconds |
|
| ms | Milliseconds | The input is indicated as time in milliseconds |
|
||||||
| us | Microseconds | The input is indicated as time in microseconds |
|
| us | Microseconds | The input is indicated as time in microseconds |
|
||||||
| B | Bytes | The input is indicated as quantity in bytes |
|
| B | Bytes | The input is indicated as quantity in bytes |
|
||||||
| KB | Kilobytes | The input is indicated as quantity in kilobytes |
|
| KB | Kilobytes | The input is indicated as quantity in Kilobytes |
|
||||||
| MB | Megabytes | The input is indicated as quantity in megabytes |
|
| MB | Megabytes | The input is indicated as quantity in Megabytes |
|
||||||
| GB | Gigabytes | The input is indicated as quantity in gigabytes |
|
| GB | Gigabytes | The input is indicated as quantity in Gigabytes |
|
||||||
| TB | Terabytes | The input is indicated as quantity in terabytes |
|
| TB | Terabytes | The input is indicated as quantity in Terabytes |
|
||||||
| c | Counter | A continues counter increasing values over time |
|
| c | Counter | A continues counter increasing values over time |
|
||||||
|
|
||||||
## Object Functions
|
## Object Functions
|
||||||
|
|
|
||||||
451
doc/developerguide/10-Custom-Daemons.md
Normal file
451
doc/developerguide/10-Custom-Daemons.md
Normal file
|
|
@ -0,0 +1,451 @@
|
||||||
|
Developer Guide: Custom Daemons
|
||||||
|
===
|
||||||
|
|
||||||
|
By [installing the PowerShell Framework as service](../service/01-Install-Service.md) you have the possibility to [register custom daemons](../service/02-Register-Daemons.md) which are executed in the background. This developer guide article will assist you in creating custom daemons.
|
||||||
|
|
||||||
|
Creating A New Module
|
||||||
|
---
|
||||||
|
|
||||||
|
The best approach for creating a custom daemon is by creating an independent module which is installed in your PowerShell modules directly. This will ensure you are not overwriting your custom data with possible framework updates.
|
||||||
|
|
||||||
|
In this guide, we will assume the name of the module is `icinga-psdaemon-agentservice`.
|
||||||
|
|
||||||
|
At first we will have to create a new module. Navigate to the PowerShell modules folder the Framework itself is installed to. In this tutorial we will assume the location is
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
C:\Program Files\WindowsPowerShell\Modules
|
||||||
|
```
|
||||||
|
|
||||||
|
Now create a new folder with the name `icinga-psdaemon-agentservice` and navigate into it.
|
||||||
|
|
||||||
|
As we require a `psm1` file which contains our code, we will create a new file with the name `icinga-psdaemon-agentservice.psm1`. This will allow the PowerShell autoloader to load the module automaticly.
|
||||||
|
|
||||||
|
**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
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
Unblock-File -Path 'C:\Program Files\WindowsPowerShell\Modules\icinga-psdaemon-agentservice\icinga-psdaemon-agentservice.psm1'
|
||||||
|
```
|
||||||
|
|
||||||
|
Testing The Module
|
||||||
|
---
|
||||||
|
|
||||||
|
Once the modules 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-psdaemon-agentservice.psm1` in your prefered editor and add the following code snippet
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
function Test-MyIcingaAgentServiceCommand()
|
||||||
|
{
|
||||||
|
Write-Host 'Module was loaded';
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Now open a **new** PowerShell terminal or write `powershell` into an already open PowerShell prompt and execute the command `Test-MyIcingaAgentServiceCommand`.
|
||||||
|
|
||||||
|
If everything went properly, you should now read the output `Module was loaded` in our prompt. If not, you can try to import the module by using
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
Import-Module 'C:\Program Files\WindowsPowerShell\Modules\icinga-psdaemon-agentservice\icinga-psdaemon-agentservice.psm1';
|
||||||
|
```
|
||||||
|
|
||||||
|
inside your console prompt. After that try again to execute the command `Test-MyIcingaAgentServiceCommand` and check if it works this time. If not, you might check the naming of your module to ensure `folder name` and `.psm1 file name` is identical.
|
||||||
|
|
||||||
|
Create A New function
|
||||||
|
---
|
||||||
|
|
||||||
|
Once everything is working properly we can create our starting function we will later use for [registering our daemon](../service/02-Register-Daemons.md).
|
||||||
|
|
||||||
|
For naming guidelines we will have to begin with the `Start` naming and an identifier of what are going to achieve with our daemon. In our example we will frequently check if the Icinga 2 agent service is active and running. In case it failed, we will restart the service.
|
||||||
|
|
||||||
|
So lets get started with the function
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
function Start-IcingaAgentServiceTest()
|
||||||
|
{
|
||||||
|
# Our code belongs here
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Basic Daemon Architecture
|
||||||
|
---
|
||||||
|
|
||||||
|
A basic daemon contains of two parts. At first we require a `ScriptBlock` with our code to execute and second a `new thread` we can create with the Cmdlet `New-IcingaThreadInstance`.
|
||||||
|
|
||||||
|
Each daemon must spawn within an own thread to ensure we are not blocking the execution of other deamons and interfere with the framework loader.
|
||||||
|
|
||||||
|
Writing Our ScriptBlock
|
||||||
|
---
|
||||||
|
|
||||||
|
As we start a new thread, we will require at first a variable to contain our actual code we wish to execute inside the thread. This can be done by using `ScriptBlocks`.
|
||||||
|
|
||||||
|
At first we will create a variable inside our `Start-IcingaAgentServiceTest` function.
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
function Start-IcingaAgentServiceTest()
|
||||||
|
{
|
||||||
|
# Our ScriptBlock for the code being executed inside the thread
|
||||||
|
[ScriptBlock]$IcingaServiceTest = {
|
||||||
|
# Everything which will be executed inside the thread
|
||||||
|
# belongs here
|
||||||
|
};
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Depending on our daemon, later usage and possible sharing of data between all loaded daemons might be required. In addition we might want to spawn child threads as single tasks being executed. To do so, we will parse the frameworks `global` data to the thread.
|
||||||
|
|
||||||
|
Our recommendation is to always do this for every daemon, as later changes might be more complicated and time consuming.
|
||||||
|
|
||||||
|
To be able to parse an argument to your script block, we will use the `param` argument.
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
function Start-IcingaAgentServiceTest()
|
||||||
|
{
|
||||||
|
# Our ScriptBlock for the code being executed inside the thread
|
||||||
|
[ScriptBlock]$IcingaServiceTest = {
|
||||||
|
# Allow us to parse the framework global data to this thread
|
||||||
|
param($IcingaDaemonData);
|
||||||
|
|
||||||
|
# Everything which will be executed inside the thread
|
||||||
|
# belongs here
|
||||||
|
};
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Now as the basic part is finished, we will require to make our framework libraries aavailable within this thread. To do so, we will initialse the framework with the `Use-Icinga` Cmdlet, do however only import libraries and tell the framework that the wish to utilize it as `daemon`. The last part is important, as this will change the handling for writing console outputs and instead of an `exit` for certain failures the module will log them internally.
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
function Start-IcingaAgentServiceTest()
|
||||||
|
{
|
||||||
|
# Our ScriptBlock for the code being executed inside the thread
|
||||||
|
[ScriptBlock]$IcingaServiceTest = {
|
||||||
|
# Allow us to parse the framework global data to this thread
|
||||||
|
param($IcingaDaemonData);
|
||||||
|
|
||||||
|
# Import the framework library components and initialise it
|
||||||
|
# as daemon
|
||||||
|
Use-Icinga -LibOnly -Daemon;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
As we will parse the `global` framework data anyways, we should already make use of it. In this case, we will write the current service state of Icinga 2 into a global `synchronized` hashtable. Before we can do this, we will have to add a new hashtable to our background daemons
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
function Start-IcingaAgentServiceTest()
|
||||||
|
{
|
||||||
|
# Our ScriptBlock for the code being executed inside the thread
|
||||||
|
[ScriptBlock]$IcingaServiceTest = {
|
||||||
|
# Allow us to parse the framework global data to this thread
|
||||||
|
param($IcingaDaemonData);
|
||||||
|
|
||||||
|
# Import the framework library components and initialise it
|
||||||
|
# as daemon
|
||||||
|
Use-Icinga -LibOnly -Daemon;
|
||||||
|
|
||||||
|
# Add a synchronized hashtable to the global data background
|
||||||
|
# daemon hashtable to write data to. In addition it will
|
||||||
|
# allow to share data collected from this daemon with others
|
||||||
|
$IcingaDaemonData.BackgroundDaemon.Add(
|
||||||
|
'TestIcingaAgentService',
|
||||||
|
[hashtable]::Synchronized(@{})
|
||||||
|
);
|
||||||
|
# This will add another hashtable to our previous
|
||||||
|
# TestIcingaAgentService hashtable to store actual service
|
||||||
|
# information
|
||||||
|
$IcingaDaemonData.BackgroundDaemon.TestIcingaAgentService.Add(
|
||||||
|
'ServiceState',
|
||||||
|
[hashtable]::Synchronized(@{})
|
||||||
|
);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
As now our base skeleton for daemon is ready we can start to write the actual part which will execute the code to check for our Icinga Agent service state.
|
||||||
|
|
||||||
|
Because the code is executed as separate thread, we will have to ensure it will run as long as the PowerShell service is being executed. This will be done with a simple `while` loop
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
function Start-IcingaAgentServiceTest()
|
||||||
|
{
|
||||||
|
# Our ScriptBlock for the code being executed inside the thread
|
||||||
|
[ScriptBlock]$IcingaServiceTest = {
|
||||||
|
# Allow us to parse the framework global data to this thread
|
||||||
|
param($IcingaDaemonData);
|
||||||
|
|
||||||
|
# Import the framework library components and initialise it
|
||||||
|
# as daemon
|
||||||
|
Use-Icinga -LibOnly -Daemon;
|
||||||
|
|
||||||
|
# Add a synchronized hashtable to the global data background
|
||||||
|
# daemon hashtable to write data to. In addition it will
|
||||||
|
# allow to share data collected from this daemon with others
|
||||||
|
$IcingaDaemonData.BackgroundDaemon.Add(
|
||||||
|
'TestIcingaAgentService',
|
||||||
|
[hashtable]::Synchronized(@{})
|
||||||
|
);
|
||||||
|
# This will add another hashtable to our previous
|
||||||
|
# TestIcingaAgentService hashtable to store actual service
|
||||||
|
# information
|
||||||
|
$IcingaDaemonData.BackgroundDaemon.TestIcingaAgentService.Add(
|
||||||
|
'ServiceState',
|
||||||
|
[hashtable]::Synchronized(@{})
|
||||||
|
);
|
||||||
|
|
||||||
|
# Keep our code excuted as long as the PowerShell service is
|
||||||
|
# being executed. This is required to ensure we will execute
|
||||||
|
# the code frequently instead of only once
|
||||||
|
while ($TRUE) {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
*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`.
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
function Start-IcingaAgentServiceTest()
|
||||||
|
{
|
||||||
|
# Our ScriptBlock for the code being executed inside the thread
|
||||||
|
[ScriptBlock]$IcingaServiceTest = {
|
||||||
|
# Allow us to parse the framework global data to this thread
|
||||||
|
param($IcingaDaemonData);
|
||||||
|
|
||||||
|
# Import the framework library components and initialise it
|
||||||
|
# as daemon
|
||||||
|
Use-Icinga -LibOnly -Daemon;
|
||||||
|
|
||||||
|
# Add a synchronized hashtable to the global data background
|
||||||
|
# daemon hashtable to write data to. In addition it will
|
||||||
|
# allow to share data collected from this daemon with others
|
||||||
|
$IcingaDaemonData.BackgroundDaemon.Add(
|
||||||
|
'TestIcingaAgentService',
|
||||||
|
[hashtable]::Synchronized(@{})
|
||||||
|
);
|
||||||
|
# This will add another hashtable to our previous
|
||||||
|
# TestIcingaAgentService hashtable to store actual service
|
||||||
|
# information
|
||||||
|
$IcingaDaemonData.BackgroundDaemon.TestIcingaAgentService.Add(
|
||||||
|
'ServiceState',
|
||||||
|
[hashtable]::Synchronized(@{})
|
||||||
|
);
|
||||||
|
|
||||||
|
# Keep our code excuted as long as the PowerShell service is
|
||||||
|
# being executed. This is required to ensure we will execute
|
||||||
|
# the code frequently instead of only once
|
||||||
|
while ($TRUE) {
|
||||||
|
# ALWAYS add some sort of sleep at the end. Either to
|
||||||
|
# break the CPU cycle and give it some break or to
|
||||||
|
# ensure daemon tasks are executed on a certain interval
|
||||||
|
Start-Sleep -Seconds 5;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
This is basicly the foundation of every single daemon you will write. Now we will add the actual task our daemon will execute while it is running. As mentioned before, we will test if our Icinga 2 Agent service is running and restart it if it is stopped. To keep track of the current status and possible errors during restart, we will add additional `synchronized` hashtables to store the `value` of the current service status and possible `restart_error` counts. To count the `restart_error` we will have to initiliase a single variable we name `$RestartErrors` before we enter our `while` loop.
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
function Start-IcingaAgentServiceTest()
|
||||||
|
{
|
||||||
|
# Our ScriptBlock for the code being executed inside the thread
|
||||||
|
[ScriptBlock]$IcingaServiceTest = {
|
||||||
|
# Allow us to parse the framework global data to this thread
|
||||||
|
param($IcingaDaemonData);
|
||||||
|
|
||||||
|
# Import the framework library components and initialise it
|
||||||
|
# as daemon
|
||||||
|
Use-Icinga -LibOnly -Daemon;
|
||||||
|
|
||||||
|
# Add a synchronized hashtable to the global data background
|
||||||
|
# daemon hashtable to write data to. In addition it will
|
||||||
|
# allow to share data collected from this daemon with others
|
||||||
|
$IcingaDaemonData.BackgroundDaemon.Add(
|
||||||
|
'TestIcingaAgentService',
|
||||||
|
[hashtable]::Synchronized(@{})
|
||||||
|
);
|
||||||
|
# This will add another hashtable to our previous
|
||||||
|
# TestIcingaAgentService hashtable to store actual service
|
||||||
|
# information
|
||||||
|
$IcingaDaemonData.BackgroundDaemon.TestIcingaAgentService.Add(
|
||||||
|
'ServiceState',
|
||||||
|
[hashtable]::Synchronized(@{})
|
||||||
|
);
|
||||||
|
|
||||||
|
# Initialise our error counter variable
|
||||||
|
[int]$RestartErrors = 0;
|
||||||
|
|
||||||
|
# Keep our code excuted as long as the PowerShell service is
|
||||||
|
# being executed. This is required to ensure we will execute
|
||||||
|
# the code frequently instead of only once
|
||||||
|
while ($TRUE) {
|
||||||
|
# Get the current service information. If the service is
|
||||||
|
# not installed, continue silently to return $null
|
||||||
|
$ServiceState = Get-Service 'icinga2' -ErrorAction SilentlyContinue;
|
||||||
|
|
||||||
|
# Only execute our code if the Icinga Agent service is
|
||||||
|
# installed
|
||||||
|
if ($null -ne $ServiceState) {
|
||||||
|
# Add the current service state to our hashtable.
|
||||||
|
Add-IcingaHashtableItem `
|
||||||
|
-Hashtable $IcingaDaemonData.BackgroundDaemon.TestIcingaAgentService.ServiceState `
|
||||||
|
-Key 'value' `
|
||||||
|
-Value $ServiceState.Status `
|
||||||
|
-Override | Out-Null;
|
||||||
|
|
||||||
|
# Restart the service if it is not running
|
||||||
|
if ($ServiceState.Status -ne 'Running') {
|
||||||
|
try {
|
||||||
|
# Try to restart the service
|
||||||
|
Restart-Service 'icinga2';
|
||||||
|
} catch {
|
||||||
|
# Add an error counter in case we failed
|
||||||
|
$RestartErrors += 1;
|
||||||
|
Add-IcingaHashtableItem `
|
||||||
|
-Hashtable $IcingaDaemonData.BackgroundDaemon.TestIcingaAgentService.ServiceState `
|
||||||
|
-Key 'restart_error' `
|
||||||
|
-Value $RestartErrors `
|
||||||
|
-Override | Out-Null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
# ALWAYS add some sort of sleep at the end. Either to
|
||||||
|
# break the CPU cycle and give it some break or to
|
||||||
|
# ensure daemon tasks are executed on a certain interval
|
||||||
|
Start-Sleep -Seconds 5;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Calling Our ScriptBlock
|
||||||
|
---
|
||||||
|
|
||||||
|
Once our SciptBlock is completed we only require to call it once our daemon is registered. Do to so, we will use the Cmdlet `New-IcingaThreadInstance`.
|
||||||
|
|
||||||
|
As arguments we will have to add a unique `name` to use for this thread as well as a `thread pool` we will add add the thread to. In our case we will use the Frameworks default pool. Last but not least we require to parse our `ScriptBlock`, possible `Arguments` and tell the thread to `Start` right after being created. For the arguments we will parse the frameworks `global` `IcingaDaemonData` we also use inside our ScriptBlock to store data in.
|
||||||
|
|
||||||
|
The function will be a added at the very bottom of our `Start-IcingaAgentServiceTest` function
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
function Start-IcingaAgentServiceTest()
|
||||||
|
{
|
||||||
|
# Our ScriptBlock for the code being executed inside the thread
|
||||||
|
[ScriptBlock]$IcingaServiceTest = {
|
||||||
|
# Allow us to parse the framework global data to this thread
|
||||||
|
param($IcingaDaemonData);
|
||||||
|
|
||||||
|
# Import the framework library components and initialise it
|
||||||
|
# as daemon
|
||||||
|
Use-Icinga -LibOnly -Daemon;
|
||||||
|
|
||||||
|
# Add a synchronized hashtable to the global data background
|
||||||
|
# daemon hashtable to write data to. In addition it will
|
||||||
|
# allow to share data collected from this daemon with others
|
||||||
|
$IcingaDaemonData.BackgroundDaemon.Add(
|
||||||
|
'TestIcingaAgentService',
|
||||||
|
[hashtable]::Synchronized(@{})
|
||||||
|
);
|
||||||
|
# This will add another hashtable to our previous
|
||||||
|
# TestIcingaAgentService hashtable to store actual service
|
||||||
|
# information
|
||||||
|
$IcingaDaemonData.BackgroundDaemon.TestIcingaAgentService.Add(
|
||||||
|
'ServiceState',
|
||||||
|
[hashtable]::Synchronized(@{})
|
||||||
|
);
|
||||||
|
|
||||||
|
# Initialise our error counter variable
|
||||||
|
[int]$RestartErrors = 0;
|
||||||
|
|
||||||
|
# Keep our code excuted as long as the PowerShell service is
|
||||||
|
# being executed. This is required to ensure we will execute
|
||||||
|
# the code frequently instead of only once
|
||||||
|
while ($TRUE) {
|
||||||
|
# Get the current service information. If the service is
|
||||||
|
# not installed, continue silently to return $null
|
||||||
|
$ServiceState = Get-Service 'icinga2' -ErrorAction SilentlyContinue;
|
||||||
|
|
||||||
|
# Only execute our code if the Icinga Agent service is
|
||||||
|
# installed
|
||||||
|
if ($null -ne $ServiceState) {
|
||||||
|
# Add the current service state to our hashtable.
|
||||||
|
Add-IcingaHashtableItem `
|
||||||
|
-Hashtable $IcingaDaemonData.BackgroundDaemon.TestIcingaAgentService.ServiceState `
|
||||||
|
-Key 'value' `
|
||||||
|
-Value $ServiceState.Status `
|
||||||
|
-Override | Out-Null;
|
||||||
|
|
||||||
|
# Restart the service if it is not running
|
||||||
|
if ($ServiceState.Status -ne 'Running') {
|
||||||
|
try {
|
||||||
|
# Try to restart the service
|
||||||
|
Restart-Service 'icinga2';
|
||||||
|
} catch {
|
||||||
|
# Add an error counter in case we failed
|
||||||
|
$RestartErrors += 1;
|
||||||
|
Add-IcingaHashtableItem `
|
||||||
|
-Hashtable $IcingaDaemonData.BackgroundDaemon.TestIcingaAgentService.ServiceState `
|
||||||
|
-Key 'restart_error' `
|
||||||
|
-Value $RestartErrors `
|
||||||
|
-Override | Out-Null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
# ALWAYS add some sort of sleep at the end. Either to
|
||||||
|
# break the CPU cycle and give it some break or to
|
||||||
|
# ensure daemon tasks are executed on a certain interval
|
||||||
|
Start-Sleep -Seconds 5;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
# Now create a new thread for our ScriptBlock, assign a name and
|
||||||
|
# parse all required arguments to it. Last but not least start it
|
||||||
|
# directly
|
||||||
|
New-IcingaThreadInstance `
|
||||||
|
-Name "Icinga_PowerShell_IcingaAgent_StateCheck" `
|
||||||
|
-ThreadPool $global:IcingaDaemonData.IcingaThreadPool.BackgroundPool `
|
||||||
|
-ScriptBlock $IcingaServiceTest `
|
||||||
|
-Arguments @( $global:IcingaDaemonData ) `
|
||||||
|
-Start;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Register Our Daemon
|
||||||
|
---
|
||||||
|
|
||||||
|
Now as our daemon is ready we can simply [register it](../service/02-Register-Daemons.md) by using the Framework commands
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
Register-IcingaBackgroundDaemon -Command 'Start-IcingaAgentServiceTest';
|
||||||
|
```
|
||||||
|
|
||||||
|
Once registered, you will have to restart the PowerShell service itselfs to apply the changes
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
Restart-IcingaService 'icingapowershell';
|
||||||
|
```
|
||||||
|
|
||||||
|
Thats it! Now the daemon is loaded with every start, checking for the Agent state and restart it if it is not running.
|
||||||
|
|
||||||
|
**Note:** In order to restart the Icinga Agent service, the user the PowerShell service is running with requires these kind of priviliges. Otherwise it will throw an error and the error counter will increase
|
||||||
|
|
||||||
|
Developer Console
|
||||||
|
---
|
||||||
|
|
||||||
|
During development you might want to test the current implementation and check if everything is working as intended. To do so, you require to open a PowerShell terminal as `administrator`. We would recommend to `stop` the PowerShell service in this case to prevent possible daemons writing files to the system and overwriting each others.
|
||||||
|
|
||||||
|
Once the service is stopped and your `administrative PowerShell` is open, we will have to initialise the Framework and start the background daemon component
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
Use-Icinga;
|
||||||
|
Start-IcingaPowerShellDaemon;
|
||||||
|
```
|
||||||
|
|
||||||
|
Once done you will receive back your prompt, however all registered background daemons are running. To access the collected data from daemons, you can print the content of the `global` framework data. If you wish to check if your daemon was loaded properly and data is actually written, we can access our created hashtable and get the current service state of it
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
$global:IcingaDaemonData.BackgroundDaemon.TestIcingaAgentService.ServiceState['value'];
|
||||||
|
```
|
||||||
|
|
||||||
|
In case your Icinga Agent service is intalled and your daemon is running properly, this should print the current state of the service.
|
||||||
|
|
||||||
|
Of course for more complex daemons you are able to manipulate data directly or add more detailed debug output.
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
Install the framework with the Kickstart Script
|
Install the framework with the Kickstart Script
|
||||||
===
|
===
|
||||||
|
|
||||||
The easiest way to install the framework is by using the Kickstart Script provided from [this repository](https://github.com/Icinga/icinga-framework-kickstart).
|
The easiest way to install the framework is by using the Kickstart Script provided from [this repository](https://github.com/Icinga/icinga-powershell-kickstart).
|
||||||
|
|
||||||
The code provided there will ask questions on where to install the framework and where the framework files are provided from. The code below is a straight copy of the initial required code-block. Simply open a PowerShell instance as administrator and copy the following code block into it:
|
The code provided there will ask questions on where to install the framework and where the framework files are provided from. The code below is a straight copy of the initial required code-block. Simply open a PowerShell instance as administrator and copy the following code block into it:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
Run the PowerShell Module as Windows Service
|
Run the PowerShell Framework as Windows Service
|
||||||
===
|
===
|
||||||
|
|
||||||
Requirements
|
Requirements
|
||||||
|
|
@ -8,6 +8,11 @@ As PowerShell Scripts / Modules can not be installed directly as Windows Service
|
||||||
|
|
||||||
In order to make this work, you will require the Icinga Windows Service which can be downloaded directly from the [GitHub Repository](https://github.com/Icinga/icinga-powershell-service).
|
In order to make this work, you will require the Icinga Windows Service which can be downloaded directly from the [GitHub Repository](https://github.com/Icinga/icinga-powershell-service).
|
||||||
|
|
||||||
|
Benefits
|
||||||
|
---
|
||||||
|
|
||||||
|
Running the PowerShell Framework as background service will add the possibility to register certain functions which are executed depending on their configuration / coding. One example would be to frequently collect monitoring metrics from the installed plugins, allowing you to receice an average of time for the CPU load for example.
|
||||||
|
|
||||||
Install the Service
|
Install the Service
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
@ -36,3 +41,13 @@ Install-IcingaFrameworkService -Path 'C:\Program Files\Icinga-Framework-Service\
|
||||||
You can validate if the service has been installed properly by using the Get Service Cmdlet:
|
You can validate if the service has been installed properly by using the Get Service Cmdlet:
|
||||||
|
|
||||||
Each enabled background daemon component is afterwards being started and executed.
|
Each enabled background daemon component is afterwards being started and executed.
|
||||||
|
|
||||||
|
Register Functions
|
||||||
|
---
|
||||||
|
|
||||||
|
As the service is now installed we can start to [register daemons](02-Register-Daemons.md) which are executed within an own thread within a PowerShell session. Depending on the registered function/module, additional configuration may be required.
|
||||||
|
|
||||||
|
Background Service Check
|
||||||
|
---
|
||||||
|
|
||||||
|
Once you registered the Daemon `Start-IcingaServiceCheckDaemon` with the [register functions](02-Register-Daemons.md) feature you will be able to [register service checks](10-Register-Service-Checks.md) which are frequently executed to collect metrics from plugins.
|
||||||
62
doc/service/02-Register-Daemons.md
Normal file
62
doc/service/02-Register-Daemons.md
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
Register Background Daemons
|
||||||
|
===
|
||||||
|
|
||||||
|
One huge advantage of the entire PowerShell Framework for Icinga is to run the PowerShell environment as background service. Once you [installed the service](01-Install-Service.md) you can simply register functions which are executed.
|
||||||
|
|
||||||
|
Register Daemon
|
||||||
|
---
|
||||||
|
|
||||||
|
To register daemons which are executed on the backkground daemon, you can use the build in command `Register-IcingaBackgroundDaemon`. An example would be to enable the frequent service check daemon which ships with this framework
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
Register-IcingaBackgroundDaemon -Command 'Start-IcingaServiceCheckDaemon';
|
||||||
|
```
|
||||||
|
|
||||||
|
The `Start-IcingaServiceCheckDaemon` is a directly integrated PowerShell function which will itself start an own thread for executing regular service checks which have been registered.
|
||||||
|
|
||||||
|
Once you made changes, please remember to restart the PowerShell Service
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
Restart-IcingaService 'icingapowershell';
|
||||||
|
```
|
||||||
|
|
||||||
|
List Enabled Daemons
|
||||||
|
---
|
||||||
|
|
||||||
|
To list all registered background daemons you can use a build-in command for this
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
Get-IcingaBackgroundDaemons;
|
||||||
|
```
|
||||||
|
|
||||||
|
Once executed you will receive a list of all daemons which are started
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
Name Value
|
||||||
|
---- -----
|
||||||
|
Start-IcingaServiceCheckDaemon {}
|
||||||
|
```
|
||||||
|
|
||||||
|
Remove Daemons
|
||||||
|
---
|
||||||
|
|
||||||
|
Besides adding and displaying registered background daemons you can also use the unregister command to remove them
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
Unregister-IcingaBackgroundDaemon -BackgroundDaemon 'Start-IcingaServiceCheckDaemon';
|
||||||
|
```
|
||||||
|
|
||||||
|
Once you restart the PowerShell service the pending changes are applied
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
Restart-IcingaService 'icingapowershell';
|
||||||
|
```
|
||||||
|
|
||||||
|
Write Custom Daemons
|
||||||
|
---
|
||||||
|
|
||||||
|
In addition you are free to write your own extensions you can register within the framework. Every PowerShell daemon which is available within a single PowerShell session - even from different modules - can be used.
|
||||||
|
|
||||||
|
Best practice would be to create an own custom PowerShell Module which will create a new thread and executing certain tasks. Once this module is available in your PowerShell session, you can simply register and use it.
|
||||||
|
|
||||||
|
For a detailed guide you should check out the [daemon developer guide](../developerguide/10-Custom-Daemons.md).
|
||||||
85
doc/service/10-Register-Service-Checks.md
Normal file
85
doc/service/10-Register-Service-Checks.md
Normal file
|
|
@ -0,0 +1,85 @@
|
||||||
|
Register Background Service Checks
|
||||||
|
===
|
||||||
|
|
||||||
|
Once the PowerShell Framework is [installed as service](01-Install-Service.md) and you enabled the `Start-IcingaServiceCheckDaemon` daemon by [registering it](02-Register-Daemons.md), you are free to configure service checks which are frequently executed on a custom time period.
|
||||||
|
|
||||||
|
Register Service Checks
|
||||||
|
---
|
||||||
|
|
||||||
|
Registering a service check will execute them frequently on a custom defined time. To do so you will have to register the check plugin you wish you collect metrics over time and add a execution time intervall including time indexes for which averages should be calculcated for.
|
||||||
|
|
||||||
|
As example we want to frequently collect our `CPU load` values with an `check interval of 30 seconds` and calculate `averages for 1m, 3m, 5m, and 15m`.
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
Register-IcingaServiceCheck -CheckCommand 'Invoke-IcingaCheckCPU' -Interval 30 -TimeIndexes 1, 3, 5, 15;
|
||||||
|
```
|
||||||
|
|
||||||
|
Once you registered a service check, you will have to restart the PowerShell service
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
Restart-IcingaService 'icingapowershell';
|
||||||
|
```
|
||||||
|
|
||||||
|
As collected metrics are written to disk as well, a restart will not flush previous data but load it again. A quick service restart will not cause missing data points.
|
||||||
|
|
||||||
|
Once the service check is executed from the background daemon, it will add additional output to your regular check execution from Icinga 2. If we execute our `Invoke-IcingaCheckCPU` now again, we will see additional metrics based on our configuration
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
[OK] Check package "CPU Load"
|
||||||
|
| 'core_0_15'=1.17%;;;0;100 'core_0_3'=1.12%;;;0;100 'core_0_5'=1.65%;;;0;100 'core_0_1'=1.36%;;;0;100 'core_0'=0.19%;;;0;100 'core_1_1'=0.86%;;;0;100 'core_1_15'=4.59%;;;0;100 'core_1_5'=5.28%;;;0;100 'core_1_3'=1.15%;;;0;100 'core_total_5'=5.2%;;;0;100 'core_total_15'=4.32%;;;0;100 'core_total_1'=3.41%;;;0;100 'core_total_3'=3.79%;;;0;100 'core_total'=1.85%;;;0;100
|
||||||
|
```
|
||||||
|
|
||||||
|
As you can see, each time index we added for the `TimeIndexes` argument is added as separat metric to our performance output. The calculation is done by all collected values over the execution period.
|
||||||
|
|
||||||
|
List Service Checks
|
||||||
|
---
|
||||||
|
|
||||||
|
To list all registered service checks you can simply use
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
Show-IcingaRegisteredServiceChecks;
|
||||||
|
```
|
||||||
|
|
||||||
|
This will print a detailed list of all checks and their configuration
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
Service Id: 5275219864641021224811420224776891459631192206
|
||||||
|
|
||||||
|
Name Value
|
||||||
|
---- -----
|
||||||
|
CheckCommand Invoke-IcingaCheckCPU
|
||||||
|
Interval 30
|
||||||
|
Arguments
|
||||||
|
Id 5275219864641021224811420224776891459631192206
|
||||||
|
TimeIndexes {1, 3, 5, 15}
|
||||||
|
```
|
||||||
|
|
||||||
|
Modify Service Checks
|
||||||
|
---
|
||||||
|
|
||||||
|
To modify service checks you can simply use the `Register-IcingaServiceCheck` command again with the identical check command, but overwritting interval and time indexes for example
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
Register-IcingaServiceCheck -CheckCommand 'Invoke-IcingaCheckCPU' -Interval 60 -TimeIndexes 1, 3, 5, 15, 20;
|
||||||
|
```
|
||||||
|
|
||||||
|
Once you modified a service check, you will have to restart the PowerShell service
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
Restart-IcingaService 'icingapowershell';
|
||||||
|
```
|
||||||
|
|
||||||
|
Unregister Service Checks
|
||||||
|
---
|
||||||
|
|
||||||
|
If you wish to remove a service check from the daemon, you can simply unregister it with the `id` displayed on the `Show-IcingaRegisteredServiceChecks` Cmdlet
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
Unregister-IcingaServiceCheck -ServiceId 5275219864641021224811420224776891459631192206;
|
||||||
|
```
|
||||||
|
|
||||||
|
Once you removed a service check, you will have to restart the PowerShell service
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
Restart-IcingaService 'icingapowershell';
|
||||||
|
```
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
ProjectUri = 'https://github.com/Icinga/icinga-powershell-framework'
|
ProjectUri = 'https://github.com/Icinga/icinga-powershell-framework'
|
||||||
ReleaseNotes = 'https://github.com/Icinga/icinga-powershell-framework/releases'
|
ReleaseNotes = 'https://github.com/Icinga/icinga-powershell-framework/releases'
|
||||||
};
|
};
|
||||||
Version = 'v1.0.0-rc3';
|
Version = 'v1.1.0';
|
||||||
}
|
}
|
||||||
HelpInfoURI = 'https://github.com/Icinga/icinga-powershell-framework'
|
HelpInfoURI = 'https://github.com/Icinga/icinga-powershell-framework'
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@ function Get-IcingaPowerShellModuleArchive()
|
||||||
|
|
||||||
$ProgressPreference = "SilentlyContinue";
|
$ProgressPreference = "SilentlyContinue";
|
||||||
$Tag = 'master';
|
$Tag = 'master';
|
||||||
|
# Fix TLS errors while connecting to GitHub with old PowerShell versions
|
||||||
|
[Net.ServicePointManager]::SecurityProtocol = "tls12, tls11";
|
||||||
|
|
||||||
if ([string]::IsNullOrEmpty($DownloadUrl)) {
|
if ([string]::IsNullOrEmpty($DownloadUrl)) {
|
||||||
if ((Get-IcingaAgentInstallerAnswerInput -Prompt ([string]::Format('Do you provide a custom repository for "{0}"?', $ModuleName)) -Default 'n').result -eq 1) {
|
if ((Get-IcingaAgentInstallerAnswerInput -Prompt ([string]::Format('Do you provide a custom repository for "{0}"?', $ModuleName)) -Default 'n').result -eq 1) {
|
||||||
|
|
|
||||||
40
lib/core/icingaagent/finders/Find-IcingaAgentObjects.psm1
Normal file
40
lib/core/icingaagent/finders/Find-IcingaAgentObjects.psm1
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
function Find-IcingaAgentObjects()
|
||||||
|
{
|
||||||
|
param(
|
||||||
|
$Find = @(),
|
||||||
|
$OutFile = $null
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($Find.Length -eq 0) {
|
||||||
|
throw 'Please specify content you want to look for';
|
||||||
|
}
|
||||||
|
|
||||||
|
[array]$ObjectList = (Get-IcingaAgentObjectList).Split("`r`n");
|
||||||
|
[int]$lineIndex = 0;
|
||||||
|
[array]$Result = @();
|
||||||
|
|
||||||
|
foreach ($line in $ObjectList) {
|
||||||
|
if ([string]::IsNullOrEmpty($line)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($entry in $Find) {
|
||||||
|
if ($line -like $entry) {
|
||||||
|
[string]$ResultLine = [string]::Format(
|
||||||
|
'Line #{0} => "{1}"',
|
||||||
|
$lineIndex,
|
||||||
|
$line
|
||||||
|
);
|
||||||
|
$Result += $ResultLine;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$lineIndex += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ([string]::IsNullOrEmpty($OutFile)) {
|
||||||
|
Write-Output $Result;
|
||||||
|
} else {
|
||||||
|
Set-Content -Path $OutFile -Value $Result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,10 @@
|
||||||
function Get-IcingaAgentBinary()
|
function Get-IcingaAgentBinary()
|
||||||
{
|
{
|
||||||
$IcingaRootDir = Get-IcingaAgentRootDirectory;
|
$IcingaRootDir = Get-IcingaAgentRootDirectory;
|
||||||
|
if ([string]::IsNullOrEmpty($IcingaRootDir)) {
|
||||||
|
throw 'The Icinga Agent seems not to be installed';
|
||||||
|
}
|
||||||
|
|
||||||
$IcingaBinary = (Join-Path -Path $IcingaRootDir -ChildPath '\sbin\icinga2.exe');
|
$IcingaBinary = (Join-Path -Path $IcingaRootDir -ChildPath '\sbin\icinga2.exe');
|
||||||
|
|
||||||
if ((Test-Path $IcingaBinary) -eq $FALSE) {
|
if ((Test-Path $IcingaBinary) -eq $FALSE) {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
function Get-IcingaAgentObjectList()
|
||||||
|
{
|
||||||
|
$Binary = Get-IcingaAgentBinary;
|
||||||
|
$ObjectList = Start-IcingaProcess -Executable $Binary -Arguments 'object list';
|
||||||
|
|
||||||
|
return $ObjectList.Message;
|
||||||
|
}
|
||||||
|
|
@ -79,7 +79,7 @@ function Start-IcingaAgentDirectorWizard()
|
||||||
$SelfServiceAPIKey = Register-IcingaDirectorSelfServiceHost -DirectorUrl $DirectorUrl -ApiKey $SelfServiceAPIKey -Hostname (Get-IcingaHostname @Arguments) -Endpoint $Arguments.IcingaMaster;
|
$SelfServiceAPIKey = Register-IcingaDirectorSelfServiceHost -DirectorUrl $DirectorUrl -ApiKey $SelfServiceAPIKey -Hostname (Get-IcingaHostname @Arguments) -Endpoint $Arguments.IcingaMaster;
|
||||||
break;
|
break;
|
||||||
} catch {
|
} catch {
|
||||||
$SelfServiceAPIKey = (Get-IcingaAgentInstallerAnswerInput -Prompt ([string]::Format('Failed to register host within Icinga Director. Please re-enter your SelfService API Key. If this prompt continues, drop your host key at "Hosts -> {0} -> Agent"', (Get-IcingaHostname @Arguments))) -Default 'v' -DefaultInput $SelfServiceAPIKey).answer;
|
$SelfServiceAPIKey = (Get-IcingaAgentInstallerAnswerInput -Prompt ([string]::Format('Failed to register host within Icinga Director. Full error: "{0}". Please re-enter your SelfService API Key. If this prompt continues ensure you are using an Agent template or drop your host key at "Hosts -> {1} -> Agent"', $_.Exception.Message, (Get-IcingaHostname @Arguments))) -Default 'v' -DefaultInput $SelfServiceAPIKey).answer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -424,6 +424,10 @@ function Start-IcingaAgentInstallWizard()
|
||||||
} else {
|
} else {
|
||||||
$InstallerArguments += "-InstallFrameworkPlugins 0";
|
$InstallerArguments += "-InstallFrameworkPlugins 0";
|
||||||
}
|
}
|
||||||
|
} elseif ($InstallFrameworkPlugins -eq 1) {
|
||||||
|
$result = Install-IcingaFrameworkPlugins -PluginsUrl $PluginsUrl;
|
||||||
|
$InstallerArguments += "-InstallFrameworkPlugins 1";
|
||||||
|
$InstallerArguments += "-PluginsUrl '$PluginsUrl'";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($null -eq $InstallFrameworkService) {
|
if ($null -eq $InstallFrameworkService) {
|
||||||
|
|
|
||||||
|
|
@ -6,5 +6,5 @@ function Read-IcingaAgentDebugLogFile()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Get-Content -Path $Logfile -Wait;
|
Get-Content -Path $Logfile -Tail 20 -Wait;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,5 +6,5 @@ function Read-IcingaAgentLogFile()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Get-Content -Path $Logfile -Wait;
|
Get-Content -Path $Logfile -Tail 20 -Wait;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
function Write-IcingaAgentObjectList()
|
||||||
|
{
|
||||||
|
param(
|
||||||
|
[string]$Path
|
||||||
|
);
|
||||||
|
|
||||||
|
if ([string]::IsNullOrEmpty($Path)) {
|
||||||
|
throw 'Please specify a path to write the Icinga objects to';
|
||||||
|
}
|
||||||
|
|
||||||
|
$ObjectList = Get-IcingaAgentObjectList;
|
||||||
|
|
||||||
|
Set-Content -Path $Path -Value $ObjectList;
|
||||||
|
}
|
||||||
|
|
@ -5,36 +5,37 @@ function Convert-Bytes()
|
||||||
[string]$Unit
|
[string]$Unit
|
||||||
);
|
);
|
||||||
|
|
||||||
If (($Value -Match "(^[\d\.]*) ?(B|KB|MB|GB|TB|PT|Kibi|Mibi|Gibi|Tibi|Pibi)")) {
|
If (($Value -Match "(^[\d\.]*) ?(B|KB|MB|GB|TB|PT|KiB|MiB|GiB|TiB|PiB)")) {
|
||||||
[single]$CurrentValue = $Matches[1];
|
[single]$CurrentValue = $Matches[1];
|
||||||
[string]$CurrentUnit = $Matches[2];
|
[string]$CurrentUnit = $Matches[2];
|
||||||
|
|
||||||
switch ($CurrentUnit) {
|
switch ($CurrentUnit) {
|
||||||
{ 'KiBi', 'Mibi', 'Gibi', 'Tibi', 'Pibi' -contains $_} { $CurrentValue = ConvertTo-ByteIEC $CurrentValue $CurrentUnit; $boolOption = $true;}
|
{ 'KiB', 'MiB', 'GiB', 'TiB', 'PiB' -contains $_} { $CurrentValue = ConvertTo-ByteIEC $CurrentValue $CurrentUnit; $boolOption = $true;}
|
||||||
{ 'KB', 'MB', 'GB', 'TB', 'PB' -contains $_} { $CurrentValue = ConvertTo-ByteSI $CurrentValue $CurrentUnit; $boolOption = $true;}
|
{ 'KB', 'MB', 'GB', 'TB', 'PB' -contains $_} { $CurrentValue = ConvertTo-ByteSI $CurrentValue $CurrentUnit; $boolOption = $true;}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
switch ($Unit) {
|
switch ($Unit) {
|
||||||
{ 'B' -contains $_} { $FinalValue = $CurrentValue; $boolOption = $true;}
|
{ 'B' -contains $_} { $FinalValue = $CurrentValue; $boolOption = $true;}
|
||||||
{ 'KB' -contains $_} { $FinalValue = ConvertTo-KiloByte $CurrentValue -Unit B; $boolOption = $true;}
|
{ 'KB' -contains $_} { $FinalValue = ConvertTo-Kilobyte $CurrentValue -Unit B; $boolOption = $true;}
|
||||||
{ 'MB' -contains $_} { $FinalValue = ConvertTo-MegaByte $CurrentValue -Unit B; $boolOption = $true;}
|
{ 'MB' -contains $_} { $FinalValue = ConvertTo-Megabyte $CurrentValue -Unit B; $boolOption = $true;}
|
||||||
{ 'GB' -contains $_} { $FinalValue = ConvertTo-GigaByte $CurrentValue -Unit B; $boolOption = $true;}
|
{ 'GB' -contains $_} { $FinalValue = ConvertTo-Gigabyte $CurrentValue -Unit B; $boolOption = $true;}
|
||||||
{ 'TB' -contains $_} { $FinalValue = ConvertTo-TeraByte $CurrentValue -Unit B; $boolOption = $true;}
|
{ 'TB' -contains $_} { $FinalValue = ConvertTo-Terabyte $CurrentValue -Unit B; $boolOption = $true;}
|
||||||
{ 'PT' -contains $_} { $FinalValue = ConvertTo-PetaByte $CurrentValue -Unit B; $boolOption = $true;}
|
{ 'PB' -contains $_} { $FinalValue = ConvertTo-Petabyte $CurrentValue -Unit B; $boolOption = $true;}
|
||||||
{ 'Kibi' -contains $_} { $FinalValue = ConvertTo-KibiByte $CurrentValue -Unit B; $boolOption = $true;}
|
{ 'KiB' -contains $_} { $FinalValue = ConvertTo-Kibibyte $CurrentValue -Unit B; $boolOption = $true;}
|
||||||
{ 'Mibi' -contains $_} { $FinalValue = ConvertTo-MibiByte $CurrentValue -Unit B; $boolOption = $true;}
|
{ 'MiB' -contains $_} { $FinalValue = ConvertTo-Mebibyte $CurrentValue -Unit B; $boolOption = $true;}
|
||||||
{ 'Gibi' -contains $_} { $FinalValue = ConvertTo-GibiByte $CurrentValue -Unit B; $boolOption = $true;}
|
{ 'GiB' -contains $_} { $FinalValue = ConvertTo-Gibibyte $CurrentValue -Unit B; $boolOption = $true;}
|
||||||
{ 'Tibi' -contains $_} { $FinalValue = ConvertTo-TibiByte $CurrentValue -Unit B; $boolOption = $true;}
|
{ 'TiB' -contains $_} { $FinalValue = ConvertTo-Tebibyte $CurrentValue -Unit B; $boolOption = $true;}
|
||||||
{ 'Piti' -contains $_} { $FinalValue = ConvertTo-PetaByte $CurrentValue -Unit B; $boolOption = $true;}
|
{ 'PiB' -contains $_} { $FinalValue = ConvertTo-Petabyte $CurrentValue -Unit B; $boolOption = $true;}
|
||||||
|
|
||||||
default {
|
default {
|
||||||
if (-Not $boolOption) {
|
if (-Not $boolOption) {
|
||||||
Throw 'Invalid input';
|
Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return @{'value' = $FinalValue; 'pastunit' = $CurrentUnit; 'endunit' = $Unit};
|
return @{'value' = $FinalValue; 'pastunit' = $CurrentUnit; 'endunit' = $Unit};
|
||||||
}
|
}
|
||||||
Throw 'Invalid input';
|
|
||||||
|
Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force;
|
||||||
}
|
}
|
||||||
|
|
@ -7,14 +7,14 @@ function ConvertTo-ByteIEC()
|
||||||
|
|
||||||
switch ($Unit) {
|
switch ($Unit) {
|
||||||
{ 'B', 'Byte' -contains $_ } { $result = $Value; $boolOption = $true; }
|
{ 'B', 'Byte' -contains $_ } { $result = $Value; $boolOption = $true; }
|
||||||
{ 'Kibi', 'KibiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; }
|
{ 'KiB', 'Kibibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; }
|
||||||
{ 'Mibi', 'MibiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 20)); $boolOption = $true; }
|
{ 'MiB', 'Mebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 20)); $boolOption = $true; }
|
||||||
{ 'Gibi', 'GibiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 30)); $boolOption = $true; }
|
{ 'GiB', 'Gibibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 30)); $boolOption = $true; }
|
||||||
{ 'Tibi', 'TibiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 40)); $boolOption = $true; }
|
{ 'TiB', 'Tebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 40)); $boolOption = $true; }
|
||||||
{ 'Piti', 'PitiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 50)); $boolOption = $true; }
|
{ 'PiB', 'Pebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 50)); $boolOption = $true; }
|
||||||
default {
|
default {
|
||||||
if (-Not $boolOption) {
|
if (-Not $boolOption) {
|
||||||
Throw 'Invalid input';
|
Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -22,7 +22,7 @@ function ConvertTo-ByteIEC()
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function ConvertTo-KibiByte()
|
function ConvertTo-Kibibyte()
|
||||||
{
|
{
|
||||||
param(
|
param(
|
||||||
[single]$Value,
|
[single]$Value,
|
||||||
|
|
@ -31,14 +31,14 @@ function ConvertTo-KibiByte()
|
||||||
|
|
||||||
switch ($Unit) {
|
switch ($Unit) {
|
||||||
{ 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(2, 10)); $boolOption = $true; }
|
{ 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(2, 10)); $boolOption = $true; }
|
||||||
{ 'Kibi', 'KibiByte' -contains $_ } { $result = $Value; $boolOption = $true; }
|
{ 'KiB', 'Kibibyte' -contains $_ } { $result = $Value; $boolOption = $true; }
|
||||||
{ 'Mibi', 'MibiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; }
|
{ 'MiB', 'Mebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; }
|
||||||
{ 'Gibi', 'GibiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 20)); $boolOption = $true; }
|
{ 'GiB', 'Gibibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 20)); $boolOption = $true; }
|
||||||
{ 'Tibi', 'TibiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 30)); $boolOption = $true; }
|
{ 'TiB', 'Tebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 30)); $boolOption = $true; }
|
||||||
{ 'Piti', 'PitiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 40)); $boolOption = $true; }
|
{ 'PiB', 'Pebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 40)); $boolOption = $true; }
|
||||||
default {
|
default {
|
||||||
if (-Not $boolOption) {
|
if (-Not $boolOption) {
|
||||||
Throw 'Invalid input';
|
Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -46,7 +46,7 @@ function ConvertTo-KibiByte()
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function ConvertTo-MibiByte()
|
function ConvertTo-Mebibyte()
|
||||||
{
|
{
|
||||||
param(
|
param(
|
||||||
[single]$Value,
|
[single]$Value,
|
||||||
|
|
@ -55,14 +55,14 @@ function ConvertTo-MibiByte()
|
||||||
|
|
||||||
switch ($Unit) {
|
switch ($Unit) {
|
||||||
{ 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(2, 20)); $boolOption = $true; }
|
{ 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(2, 20)); $boolOption = $true; }
|
||||||
{ 'Kibi', 'KibiByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 10)); $boolOption = $true; }
|
{ 'KiB', 'Kibibyte' -contains $_ } { $result = ($Value / [math]::Pow(2, 10)); $boolOption = $true; }
|
||||||
{ 'Mibi', 'MibiByte' -contains $_ } { $result = $Value; $boolOption = $true; }
|
{ 'MiB', 'Mebibyte' -contains $_ } { $result = $Value; $boolOption = $true; }
|
||||||
{ 'Gibi', 'GibiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; }
|
{ 'GiB', 'Gibibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; }
|
||||||
{ 'Tibi', 'TibiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 20)); $boolOption = $true; }
|
{ 'TiB', 'Tebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 20)); $boolOption = $true; }
|
||||||
{ 'Piti', 'PitiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 30)); $boolOption = $true; }
|
{ 'PiB', 'Pebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 30)); $boolOption = $true; }
|
||||||
default {
|
default {
|
||||||
if (-Not $boolOption) {
|
if (-Not $boolOption) {
|
||||||
Throw 'Invalid input';
|
Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -70,7 +70,7 @@ function ConvertTo-MibiByte()
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function ConvertTo-GibiByte()
|
function ConvertTo-Gibibyte()
|
||||||
{
|
{
|
||||||
param(
|
param(
|
||||||
[single]$Value,
|
[single]$Value,
|
||||||
|
|
@ -79,14 +79,14 @@ function ConvertTo-GibiByte()
|
||||||
|
|
||||||
switch ($Unit) {
|
switch ($Unit) {
|
||||||
{ 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(2, 30)); $boolOption = $true; }
|
{ 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(2, 30)); $boolOption = $true; }
|
||||||
{ 'Kibi', 'KibiByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 20)); $boolOption = $true; }
|
{ 'KiB', 'Kibibyte' -contains $_ } { $result = ($Value / [math]::Pow(2, 20)); $boolOption = $true; }
|
||||||
{ 'Mibi', 'MibiByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 10)); $boolOption = $true; }
|
{ 'MiB', 'Mebibyte' -contains $_ } { $result = ($Value / [math]::Pow(2, 10)); $boolOption = $true; }
|
||||||
{ 'Gibi', 'GibiByte' -contains $_ } { $result = $Value; $boolOption = $true; }
|
{ 'GiB', 'Gibibyte' -contains $_ } { $result = $Value; $boolOption = $true; }
|
||||||
{ 'Tibi', 'TibiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; }
|
{ 'TiB', 'Tebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; }
|
||||||
{ 'Piti', 'PitiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 20)); $boolOption = $true; }
|
{ 'PiB', 'Pebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 20)); $boolOption = $true; }
|
||||||
default {
|
default {
|
||||||
if (-Not $boolOption) {
|
if (-Not $boolOption) {
|
||||||
Throw 'Invalid input';
|
Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -94,7 +94,7 @@ function ConvertTo-GibiByte()
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function ConvertTo-TibiByte()
|
function ConvertTo-Tebibyte()
|
||||||
{
|
{
|
||||||
param(
|
param(
|
||||||
[single]$Value,
|
[single]$Value,
|
||||||
|
|
@ -103,14 +103,14 @@ function ConvertTo-TibiByte()
|
||||||
|
|
||||||
switch ($Unit) {
|
switch ($Unit) {
|
||||||
{ 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(2, 40)); $boolOption = $true; }
|
{ 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(2, 40)); $boolOption = $true; }
|
||||||
{ 'Kibi', 'KibiByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 30)); $boolOption = $true; }
|
{ 'KiB', 'Kibibyte' -contains $_ } { $result = ($Value / [math]::Pow(2, 30)); $boolOption = $true; }
|
||||||
{ 'Mibi', 'MibiByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 20)); $boolOption = $true; }
|
{ 'MiB', 'Mebibyte' -contains $_ } { $result = ($Value / [math]::Pow(2, 20)); $boolOption = $true; }
|
||||||
{ 'Gibi', 'GibiByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 10)); $boolOption = $true; }
|
{ 'GiB', 'Gibibyte' -contains $_ } { $result = ($Value / [math]::Pow(2, 10)); $boolOption = $true; }
|
||||||
{ 'Tibi', 'TibiByte' -contains $_ } { $result = $Value; $boolOption = $true; }
|
{ 'TiB', 'Tebibyte' -contains $_ } { $result = $Value; $boolOption = $true; }
|
||||||
{ 'Piti', 'PitiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; }
|
{ 'PiB', 'Pebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; }
|
||||||
default {
|
default {
|
||||||
if (-Not $boolOption) {
|
if (-Not $boolOption) {
|
||||||
Throw 'Invalid input';
|
Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -118,7 +118,7 @@ function ConvertTo-TibiByte()
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function ConvertTo-PitiByte()
|
function ConvertTo-Pebibyte()
|
||||||
{
|
{
|
||||||
param(
|
param(
|
||||||
[single]$Value,
|
[single]$Value,
|
||||||
|
|
@ -127,14 +127,14 @@ function ConvertTo-PitiByte()
|
||||||
|
|
||||||
switch ($Unit) {
|
switch ($Unit) {
|
||||||
{ 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(2, 50)); $boolOption = $true; }
|
{ 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(2, 50)); $boolOption = $true; }
|
||||||
{ 'Kibi', 'KibiByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 40)); $boolOption = $true; }
|
{ 'KiB', 'Kibibyte' -contains $_ } { $result = ($Value / [math]::Pow(2, 40)); $boolOption = $true; }
|
||||||
{ 'Mibi', 'MibiByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 30)); $boolOption = $true; }
|
{ 'MiB', 'Mebibyte' -contains $_ } { $result = ($Value / [math]::Pow(2, 30)); $boolOption = $true; }
|
||||||
{ 'Gibi', 'GibiByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 20)); $boolOption = $true; }
|
{ 'GiB', 'Gibibyte' -contains $_ } { $result = ($Value / [math]::Pow(2, 20)); $boolOption = $true; }
|
||||||
{ 'Tibi', 'TibiByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 10)); $boolOption = $true; }
|
{ 'TiB', 'Tebibyte' -contains $_ } { $result = ($Value / [math]::Pow(2, 10)); $boolOption = $true; }
|
||||||
{ 'Piti', 'PitiByte' -contains $_ } { $result = $Value; $boolOption = $true; }
|
{ 'PiB', 'Pebibyte' -contains $_ } { $result = $Value; $boolOption = $true; }
|
||||||
default {
|
default {
|
||||||
if (-Not $boolOption) {
|
if (-Not $boolOption) {
|
||||||
Throw 'Invalid input';
|
Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,14 +23,14 @@ function ConvertTo-ByteSI()
|
||||||
|
|
||||||
switch ($Unit) {
|
switch ($Unit) {
|
||||||
{ 'B', 'Byte' -contains $_ } { $result = $Value; $boolOption = $true; }
|
{ 'B', 'Byte' -contains $_ } { $result = $Value; $boolOption = $true; }
|
||||||
{ 'KB', 'KiloByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 3)); $boolOption = $true; }
|
{ 'KB', 'Kilobyte' -contains $_ } { $result = ($Value * [math]::Pow(10, 3)); $boolOption = $true; }
|
||||||
{ 'MB', 'MegaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 6)); $boolOption = $true; }
|
{ 'MB', 'Megabyte' -contains $_ } { $result = ($Value * [math]::Pow(10, 6)); $boolOption = $true; }
|
||||||
{ 'GB', 'GigaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 9)); $boolOption = $true; }
|
{ 'GB', 'Gigabyte' -contains $_ } { $result = ($Value * [math]::Pow(10, 9)); $boolOption = $true; }
|
||||||
{ 'TB', 'TeraByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 12)); $boolOption = $true; }
|
{ 'TB', 'Terabyte' -contains $_ } { $result = ($Value * [math]::Pow(10, 12)); $boolOption = $true; }
|
||||||
{ 'PT', 'PetaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 15)); $boolOption = $true; }
|
{ 'PB', 'Petabyte' -contains $_ } { $result = ($Value * [math]::Pow(10, 15)); $boolOption = $true; }
|
||||||
default {
|
default {
|
||||||
if (-Not $boolOption) {
|
if (-Not $boolOption) {
|
||||||
Throw 'Invalid input';
|
Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -40,21 +40,21 @@ function ConvertTo-ByteSI()
|
||||||
|
|
||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Converts unit sizes to kilobyte.
|
Converts unit sizes to Kilobyte.
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
This module converts a given unit size to kilobyte.
|
This module converts a given unit size to Kilobyte.
|
||||||
e.g byte to kilobyte.
|
e.g byte to Kilobyte.
|
||||||
|
|
||||||
More Information on https://github.com/Icinga/icinga-powershell-framework
|
More Information on https://github.com/Icinga/icinga-powershell-framework
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ConvertTo-KiloByte -Unit TB 200
|
PS> ConvertTo-Kilobyte -Unit TB 200
|
||||||
200000000000
|
200000000000
|
||||||
.LINK
|
.LINK
|
||||||
https://github.com/Icinga/icinga-powershell-framework
|
https://github.com/Icinga/icinga-powershell-framework
|
||||||
.NOTES
|
.NOTES
|
||||||
#>
|
#>
|
||||||
|
|
||||||
function ConvertTo-KiloByte()
|
function ConvertTo-Kilobyte()
|
||||||
{
|
{
|
||||||
param(
|
param(
|
||||||
[single]$Value,
|
[single]$Value,
|
||||||
|
|
@ -63,14 +63,14 @@ function ConvertTo-KiloByte()
|
||||||
|
|
||||||
switch ($Unit) {
|
switch ($Unit) {
|
||||||
{ 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(10, 3)); $boolOption = $true; }
|
{ 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(10, 3)); $boolOption = $true; }
|
||||||
{ 'KB', 'KiloByte' -contains $_ } { $result = $Value; $boolOption = $true; }
|
{ 'KB', 'Kilobyte' -contains $_ } { $result = $Value; $boolOption = $true; }
|
||||||
{ 'MB', 'MegaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 3)); $boolOption = $true; }
|
{ 'MB', 'Megabyte' -contains $_ } { $result = ($Value * [math]::Pow(10, 3)); $boolOption = $true; }
|
||||||
{ 'GB', 'GigaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 6)); $boolOption = $true; }
|
{ 'GB', 'Gigabyte' -contains $_ } { $result = ($Value * [math]::Pow(10, 6)); $boolOption = $true; }
|
||||||
{ 'TB', 'TeraByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 9)); $boolOption = $true; }
|
{ 'TB', 'Terabyte' -contains $_ } { $result = ($Value * [math]::Pow(10, 9)); $boolOption = $true; }
|
||||||
{ 'PT', 'PetaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 12)); $boolOption = $true; }
|
{ 'PB', 'Petabyte' -contains $_ } { $result = ($Value * [math]::Pow(10, 12)); $boolOption = $true; }
|
||||||
default {
|
default {
|
||||||
if (-Not $boolOption) {
|
if (-Not $boolOption) {
|
||||||
Throw 'Invalid input';
|
Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -80,21 +80,21 @@ function ConvertTo-KiloByte()
|
||||||
|
|
||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Converts unit sizes to megabyte.
|
Converts unit sizes to Megabyte.
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
This module converts a given unit size to megabyte.
|
This module converts a given unit size to Megabyte.
|
||||||
e.g byte to megabyte.
|
e.g byte to Megabyte.
|
||||||
|
|
||||||
More Information on https://github.com/Icinga/icinga-powershell-framework
|
More Information on https://github.com/Icinga/icinga-powershell-framework
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ConvertTo-KiloByte -Unit TB 200
|
PS> ConvertTo-Kilobyte -Unit TB 200
|
||||||
200000000
|
200000000
|
||||||
.LINK
|
.LINK
|
||||||
https://github.com/Icinga/icinga-powershell-framework
|
https://github.com/Icinga/icinga-powershell-framework
|
||||||
.NOTES
|
.NOTES
|
||||||
#>
|
#>
|
||||||
|
|
||||||
function ConvertTo-MegaByte()
|
function ConvertTo-Megabyte()
|
||||||
{
|
{
|
||||||
param(
|
param(
|
||||||
[single]$Value,
|
[single]$Value,
|
||||||
|
|
@ -103,14 +103,14 @@ function ConvertTo-MegaByte()
|
||||||
|
|
||||||
switch ($Unit) {
|
switch ($Unit) {
|
||||||
{ 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(10, 6)); $boolOption = $true; }
|
{ 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(10, 6)); $boolOption = $true; }
|
||||||
{ 'KB', 'KiloByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 3)); $boolOption = $true; }
|
{ 'KB', 'Kilobyte' -contains $_ } { $result = ($Value / [math]::Pow(10, 3)); $boolOption = $true; }
|
||||||
{ 'MB', 'MegaByte' -contains $_ } { $result = $Value; $boolOption = $true; }
|
{ 'MB', 'Megabyte' -contains $_ } { $result = $Value; $boolOption = $true; }
|
||||||
{ 'GB', 'GigaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 3)); $boolOption = $true; }
|
{ 'GB', 'Gigabyte' -contains $_ } { $result = ($Value * [math]::Pow(10, 3)); $boolOption = $true; }
|
||||||
{ 'TB', 'TeraByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 6)); $boolOption = $true; }
|
{ 'TB', 'Terabyte' -contains $_ } { $result = ($Value * [math]::Pow(10, 6)); $boolOption = $true; }
|
||||||
{ 'PT', 'PetaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 9)); $boolOption = $true; }
|
{ 'PB', 'Petabyte' -contains $_ } { $result = ($Value * [math]::Pow(10, 9)); $boolOption = $true; }
|
||||||
default {
|
default {
|
||||||
if (-Not $boolOption) {
|
if (-Not $boolOption) {
|
||||||
Throw 'Invalid input';
|
Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -120,21 +120,21 @@ function ConvertTo-MegaByte()
|
||||||
|
|
||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Converts unit sizes to gigabyte.
|
Converts unit sizes to Gigabyte.
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
This module converts a given unit size to gigabyte.
|
This module converts a given unit size to Gigabyte.
|
||||||
e.g byte to gigabyte.
|
e.g byte to Gigabyte.
|
||||||
|
|
||||||
More Information on https://github.com/Icinga/icinga-powershell-framework
|
More Information on https://github.com/Icinga/icinga-powershell-framework
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ConvertTo-GigaByte -Unit TB 200
|
PS> ConvertTo-Gigabyte -Unit TB 200
|
||||||
200000
|
200000
|
||||||
.LINK
|
.LINK
|
||||||
https://github.com/Icinga/icinga-powershell-framework
|
https://github.com/Icinga/icinga-powershell-framework
|
||||||
.NOTES
|
.NOTES
|
||||||
#>
|
#>
|
||||||
|
|
||||||
function ConvertTo-GigaByte()
|
function ConvertTo-Gigabyte()
|
||||||
{
|
{
|
||||||
param(
|
param(
|
||||||
[single]$Value,
|
[single]$Value,
|
||||||
|
|
@ -143,14 +143,14 @@ function ConvertTo-GigaByte()
|
||||||
|
|
||||||
switch ($Unit) {
|
switch ($Unit) {
|
||||||
{ 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(10, 9)); $boolOption = $true; }
|
{ 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(10, 9)); $boolOption = $true; }
|
||||||
{ 'KB', 'KiloByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 6)); $boolOption = $true; }
|
{ 'KB', 'Kilobyte' -contains $_ } { $result = ($Value / [math]::Pow(10, 6)); $boolOption = $true; }
|
||||||
{ 'MB', 'MegaByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 3)); $boolOption = $true; }
|
{ 'MB', 'Megabyte' -contains $_ } { $result = ($Value / [math]::Pow(10, 3)); $boolOption = $true; }
|
||||||
{ 'GB', 'GigaByte' -contains $_ } { $result = $Value; $boolOption = $true; }
|
{ 'GB', 'Gigabyte' -contains $_ } { $result = $Value; $boolOption = $true; }
|
||||||
{ 'TB', 'TeraByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 3)); $boolOption = $true; }
|
{ 'TB', 'Terabyte' -contains $_ } { $result = ($Value * [math]::Pow(10, 3)); $boolOption = $true; }
|
||||||
{ 'PT', 'PetaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 6)); $boolOption = $true; }
|
{ 'PB', 'Petabyte' -contains $_ } { $result = ($Value * [math]::Pow(10, 6)); $boolOption = $true; }
|
||||||
default {
|
default {
|
||||||
if (-Not $boolOption) {
|
if (-Not $boolOption) {
|
||||||
Throw 'Invalid input';
|
Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -160,21 +160,21 @@ function ConvertTo-GigaByte()
|
||||||
|
|
||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Converts unit sizes to terabyte.
|
Converts unit sizes to Terabyte.
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
This module converts a given unit size to terabyte.
|
This module converts a given unit size to Terabyte.
|
||||||
e.g byte to terabyte.
|
e.g byte to Terabyte.
|
||||||
|
|
||||||
More Information on https://github.com/Icinga/icinga-powershell-framework
|
More Information on https://github.com/Icinga/icinga-powershell-framework
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ConvertTo-TeraByte -Unit GB 2000000
|
PS> ConvertTo-Terabyte -Unit GB 2000000
|
||||||
2000
|
2000
|
||||||
.LINK
|
.LINK
|
||||||
https://github.com/Icinga/icinga-powershell-framework
|
https://github.com/Icinga/icinga-powershell-framework
|
||||||
.NOTES
|
.NOTES
|
||||||
#>
|
#>
|
||||||
|
|
||||||
function ConvertTo-TeraByte()
|
function ConvertTo-Terabyte()
|
||||||
{
|
{
|
||||||
param(
|
param(
|
||||||
[single]$Value,
|
[single]$Value,
|
||||||
|
|
@ -183,14 +183,14 @@ function ConvertTo-TeraByte()
|
||||||
|
|
||||||
switch ($Unit) {
|
switch ($Unit) {
|
||||||
{ 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(10, 12)); $boolOption = $true; }
|
{ 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(10, 12)); $boolOption = $true; }
|
||||||
{ 'KB', 'KiloByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 9)); $boolOption = $true; }
|
{ 'KB', 'Kilobyte' -contains $_ } { $result = ($Value / [math]::Pow(10, 9)); $boolOption = $true; }
|
||||||
{ 'MB', 'MegaByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 6)); $boolOption = $true; }
|
{ 'MB', 'Megabyte' -contains $_ } { $result = ($Value / [math]::Pow(10, 6)); $boolOption = $true; }
|
||||||
{ 'GB', 'GigaByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 3)); $boolOption = $true; }
|
{ 'GB', 'Gigabyte' -contains $_ } { $result = ($Value / [math]::Pow(10, 3)); $boolOption = $true; }
|
||||||
{ 'TB', 'TeraByte' -contains $_ } { $result = $Value; $boolOption = $true; }
|
{ 'TB', 'Terabyte' -contains $_ } { $result = $Value; $boolOption = $true; }
|
||||||
{ 'PT', 'PetaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 3)); $boolOption = $true; }
|
{ 'PB', 'Petabyte' -contains $_ } { $result = ($Value * [math]::Pow(10, 3)); $boolOption = $true; }
|
||||||
default {
|
default {
|
||||||
if (-Not $boolOption) {
|
if (-Not $boolOption) {
|
||||||
Throw 'Invalid input';
|
Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -200,21 +200,21 @@ function ConvertTo-TeraByte()
|
||||||
|
|
||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Converts unit sizes to petabyte.
|
Converts unit sizes to Petabyte.
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
This module converts a given unit size to petabyte.
|
This module converts a given unit size to Petabyte.
|
||||||
e.g byte to petabyte.
|
e.g byte to Petabyte.
|
||||||
|
|
||||||
More Information on https://github.com/Icinga/icinga-powershell-framework
|
More Information on https://github.com/Icinga/icinga-powershell-framework
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ConvertTo-PetaByte -Unit GB 2000000
|
PS> ConvertTo-Petabyte -Unit GB 2000000
|
||||||
2
|
2
|
||||||
.LINK
|
.LINK
|
||||||
https://github.com/Icinga/icinga-powershell-framework
|
https://github.com/Icinga/icinga-powershell-framework
|
||||||
.NOTES
|
.NOTES
|
||||||
#>
|
#>
|
||||||
|
|
||||||
function ConvertTo-PetaByte()
|
function ConvertTo-Petabyte()
|
||||||
{
|
{
|
||||||
param(
|
param(
|
||||||
[single]$Value,
|
[single]$Value,
|
||||||
|
|
@ -223,14 +223,14 @@ function ConvertTo-PetaByte()
|
||||||
|
|
||||||
switch ($Unit) {
|
switch ($Unit) {
|
||||||
{ 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(10, 15)); $boolOption = $true; }
|
{ 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(10, 15)); $boolOption = $true; }
|
||||||
{ 'KB', 'KiloByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 12)); $boolOption = $true; }
|
{ 'KB', 'Kilobyte' -contains $_ } { $result = ($Value / [math]::Pow(10, 12)); $boolOption = $true; }
|
||||||
{ 'MB', 'MegaByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 9)); $boolOption = $true; }
|
{ 'MB', 'Megabyte' -contains $_ } { $result = ($Value / [math]::Pow(10, 9)); $boolOption = $true; }
|
||||||
{ 'GB', 'GigaByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 6)); $boolOption = $true; }
|
{ 'GB', 'Gigabyte' -contains $_ } { $result = ($Value / [math]::Pow(10, 6)); $boolOption = $true; }
|
||||||
{ 'TB', 'TeraByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 3)); $boolOption = $true; }
|
{ 'TB', 'Terabyte' -contains $_ } { $result = ($Value / [math]::Pow(10, 3)); $boolOption = $true; }
|
||||||
{ 'PT', 'PetaByte' -contains $_ } { $result = $Value; $boolOption = $true; }
|
{ 'PB', 'Petabyte' -contains $_ } { $result = $Value; $boolOption = $true; }
|
||||||
default {
|
default {
|
||||||
if (-Not $boolOption) {
|
if (-Not $boolOption) {
|
||||||
Throw 'Invalid input';
|
Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ function ConvertTo-IcingaIPBinaryString()
|
||||||
param(
|
param(
|
||||||
$IP
|
$IP
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($IP -like '*.*') {
|
if ($IP -like '*.*') {
|
||||||
$IP = ConvertTo-IcingaIPv4BinaryString -IP $IP;
|
$IP = ConvertTo-IcingaIPv4BinaryString -IP $IP;
|
||||||
} elseif ($IP -like '*:*') {
|
} elseif ($IP -like '*:*') {
|
||||||
|
|
|
||||||
|
|
@ -25,11 +25,17 @@ function ConvertTo-IcingaIPv4BinaryString()
|
||||||
[string]$IP
|
[string]$IP
|
||||||
);
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
$IP = $IP -split '\.' | ForEach-Object {
|
$IP = $IP -split '\.' | ForEach-Object {
|
||||||
[System.Convert]::ToString($_, 2).PadLeft(8, '0');
|
[System.Convert]::ToString($_, 2).PadLeft(8, '0');
|
||||||
}
|
}
|
||||||
$IP = $IP -join '';
|
$IP = $IP -join '';
|
||||||
$IP = $IP -replace '\s','';
|
$IP = $IP -replace '\s','';
|
||||||
|
} catch {
|
||||||
|
# Todo: Should we handle errors? It might happen due to faulty routes or unhandled route config
|
||||||
|
# we throw errors which should have no effect at all
|
||||||
|
return $null;
|
||||||
|
}
|
||||||
|
|
||||||
return @{
|
return @{
|
||||||
'value' = $IP;
|
'value' = $IP;
|
||||||
|
|
|
||||||
|
|
@ -148,7 +148,7 @@ function Get-IcingaCheckCommandConfig()
|
||||||
}
|
}
|
||||||
|
|
||||||
# Add arguments to a given command
|
# Add arguments to a given command
|
||||||
if ($parameter.type.name -eq 'switch') {
|
if ($parameter.type.name -eq 'SwitchParameter') {
|
||||||
$Basket.Command[$Data.Name].arguments.Add(
|
$Basket.Command[$Data.Name].arguments.Add(
|
||||||
[string]::Format('-{0}', $parameter.Name), @{
|
[string]::Format('-{0}', $parameter.Name), @{
|
||||||
'set_if' = $IcingaCustomVariable;
|
'set_if' = $IcingaCustomVariable;
|
||||||
|
|
@ -160,7 +160,7 @@ function Get-IcingaCheckCommandConfig()
|
||||||
$Basket.Command[$Data.Name].vars.Add($parameter.Name, $FALSE);
|
$Basket.Command[$Data.Name].vars.Add($parameter.Name, $FALSE);
|
||||||
|
|
||||||
# Conditional whether type of parameter is array
|
# Conditional whether type of parameter is array
|
||||||
} elseif ($parameter.type.name -eq 'array') {
|
} elseif ($parameter.type.name -eq 'Array') {
|
||||||
$Basket.Command[$Data.Name].arguments.Add(
|
$Basket.Command[$Data.Name].arguments.Add(
|
||||||
[string]::Format('-{0}', $parameter.Name), @{
|
[string]::Format('-{0}', $parameter.Name), @{
|
||||||
'value' = @{
|
'value' = @{
|
||||||
|
|
@ -250,7 +250,7 @@ function Get-IcingaCheckCommandConfig()
|
||||||
$Basket.Datafield[[string]$FieldID].Add(
|
$Basket.Datafield[[string]$FieldID].Add(
|
||||||
'settings', @{
|
'settings', @{
|
||||||
'datalist' = $DataListName;
|
'datalist' = $DataListName;
|
||||||
'datatype' = 'string';
|
'data_type' = 'string';
|
||||||
'behavior' = 'strict';
|
'behavior' = 'strict';
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ function Get-IcingaNetworkInterface()
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$IP = ([System.Net.Dns]::GetHostAddresses($IP)).IPAddressToString;
|
[array]$IP = ([System.Net.Dns]::GetHostAddresses($IP)).IPAddressToString;
|
||||||
} catch {
|
} catch {
|
||||||
Write-Host 'Invalid IP was provided!';
|
Write-Host 'Invalid IP was provided!';
|
||||||
return $null;
|
return $null;
|
||||||
|
|
@ -54,21 +54,47 @@ function Get-IcingaNetworkInterface()
|
||||||
$Counter++;
|
$Counter++;
|
||||||
|
|
||||||
$Divide = $Info.DestinationPrefix;
|
$Divide = $Info.DestinationPrefix;
|
||||||
$IP,$Mask = $Divide.Split('/');
|
$IP, $Mask = $Divide.Split('/');
|
||||||
|
|
||||||
|
foreach ($destinationIP in $IPBinStringMaster) {
|
||||||
|
[string]$Key = '';
|
||||||
|
[string]$MaskKey = '';
|
||||||
############################################################################
|
############################################################################
|
||||||
################################ IPv4 ####################################
|
################################ IPv4 ####################################
|
||||||
############################################################################
|
############################################################################
|
||||||
if ($IPBinStringMaster.name -eq 'IPv4') {
|
if ($destinationIP.name -eq 'IPv4') {
|
||||||
if ($IP -like '*.*') {
|
if ($IP -like '*.*') {
|
||||||
############################################################################
|
############################################################################
|
||||||
if ([int]$Mask -lt 10) {
|
if ([int]$Mask -lt 10) {
|
||||||
[string]$MaskKey = [string]::Format('00{0}', $Mask);
|
$MaskKey = [string]::Format('00{0}', $Mask);
|
||||||
} else {
|
} else {
|
||||||
[string]$MaskKey = [string]::Format('0{0}', $Mask);
|
$MaskKey = [string]::Format('0{0}', $Mask);
|
||||||
|
}
|
||||||
|
############################################################################
|
||||||
|
}
|
||||||
|
}
|
||||||
|
############################################################################
|
||||||
|
################################ IPv6 ####################################
|
||||||
|
############################################################################
|
||||||
|
if ($destinationIP.name -eq 'IPv6') {
|
||||||
|
if ($IP -like '*:*') {
|
||||||
|
############################################################################
|
||||||
|
if ([int]$Mask -lt 10) {
|
||||||
|
$MaskKey = [string]::Format('00{0}', $Mask);
|
||||||
|
} elseif ([int]$Mask -lt 100) {
|
||||||
|
$MaskKey = [string]::Format('0{0}', $Mask);
|
||||||
|
} else {
|
||||||
|
$MaskKey = $Mask;
|
||||||
|
}
|
||||||
|
############################################################################
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[string]$Key = [string]::Format('{0}-{1}', $MaskKey, $Counter);
|
$Key = [string]::Format('{0}-{1}', $MaskKey, $Counter);
|
||||||
|
|
||||||
|
if ($InterfaceData.ContainsKey($Key)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$InterfaceData.Add(
|
$InterfaceData.Add(
|
||||||
$Key, @{
|
$Key, @{
|
||||||
|
|
@ -77,48 +103,69 @@ function Get-IcingaNetworkInterface()
|
||||||
'Interface' = $Info.ifIndex;
|
'Interface' = $Info.ifIndex;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
############################################################################
|
|
||||||
}
|
|
||||||
}
|
|
||||||
############################################################################
|
|
||||||
################################ IPv4 ####################################
|
|
||||||
############################################################################
|
|
||||||
if ($IPBinStringMaster.name -eq 'IPv6') {
|
|
||||||
if ($IP -like '*:*') {
|
|
||||||
############################################################################
|
|
||||||
if ([int]$Mask -lt 10) {
|
|
||||||
[string]$MaskKey = [string]::Format('00{0}', $Mask);
|
|
||||||
} elseif ([int]$Mask -lt 100) {
|
|
||||||
[string]$MaskKey = [string]::Format('0{0}', $Mask);
|
|
||||||
} else {
|
|
||||||
[string]$MaskKey = $Mask;
|
|
||||||
}
|
|
||||||
|
|
||||||
[string]$Key = [string]::Format('{0}-{1}', $MaskKey, $Counter);
|
|
||||||
|
|
||||||
$InterfaceData.Add(
|
|
||||||
$Key, @{
|
|
||||||
'Binary IP String' = (ConvertTo-IcingaIPBinaryString -IP $IP);
|
|
||||||
'Mask' = $Mask;
|
|
||||||
'Interface' = $Info.ifIndex;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
############################################################################
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$InterfaceDataOrdered = $InterfaceData.GetEnumerator() | Sort-Object -Property Name -Descending;
|
$InterfaceDataOrdered = $InterfaceData.GetEnumerator() | Sort-Object -Property Name -Descending;
|
||||||
|
$ExternalInterfaces = @{};
|
||||||
|
|
||||||
foreach ( $Route in $InterfaceDataOrdered ) {
|
foreach ( $Route in $InterfaceDataOrdered ) {
|
||||||
|
foreach ($destinationIP in $IPBinStringMaster) {
|
||||||
[string]$RegexPattern = [string]::Format("^.{{{0}}}", $Route.Value.Mask);
|
[string]$RegexPattern = [string]::Format("^.{{{0}}}", $Route.Value.Mask);
|
||||||
[string]$ToBeMatched = $Route.Value."Binary IP String";
|
[string]$ToBeMatched = $Route.Value."Binary IP String";
|
||||||
|
if ($null -eq $ToBeMatched) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$Match1=[regex]::Matches($ToBeMatched, $RegexPattern).Value;
|
$Match1=[regex]::Matches($ToBeMatched, $RegexPattern).Value;
|
||||||
$Match2=[regex]::Matches($IPBinStringMaster.Value, $RegexPattern).Value;
|
$Match2=[regex]::Matches($destinationIP.Value, $RegexPattern).Value;
|
||||||
|
|
||||||
If ($Match1 -like $Match2) {
|
If ($Match1 -like $Match2) {
|
||||||
return ((Get-NetIPAddress -InterfaceIndex $Route.Value.Interface -AddressFamily $IPBinStringMaster.name).IPAddress);
|
$ExternalInterface = ((Get-NetIPAddress -InterfaceIndex $Route.Value.Interface -AddressFamily $destinationIP.Name -ErrorAction SilentlyContinue).IPAddress);
|
||||||
|
|
||||||
|
# If no interface was found -> skip this entry
|
||||||
|
if ($null -eq $ExternalInterface) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($ExternalInterfaces.ContainsKey($ExternalInterface)) {
|
||||||
|
$ExternalInterfaces[$ExternalInterface].count += 1;
|
||||||
|
} else {
|
||||||
|
$ExternalInterfaces.Add(
|
||||||
|
$ExternalInterface,
|
||||||
|
@{
|
||||||
|
'count' = 1
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ((Get-NetIPAddress -InterfaceIndex (Get-NetRoute | Where-Object -Property DestinationPrefix -like '0.0.0.0/0')[0].IfIndex -AddressFamily $IPBinStringMaster.name).IPAddress).split('%')[0];
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($ExternalInterfaces.Count -eq 0) {
|
||||||
|
foreach ($destinationIP in $IPBinStringMaster) {
|
||||||
|
$ExternalInterface = ((Get-NetIPAddress -InterfaceIndex (Get-NetRoute | Where-Object -Property DestinationPrefix -like '0.0.0.0/0')[0].IfIndex -AddressFamily $destinationIP.name).IPAddress).split('%')[0];
|
||||||
|
if ($ExternalInterfaces.ContainsKey($ExternalInterface)) {
|
||||||
|
$ExternalInterfaces[$ExternalInterface].count += 1;
|
||||||
|
} else {
|
||||||
|
$ExternalInterfaces.Add(
|
||||||
|
$ExternalInterface,
|
||||||
|
@{
|
||||||
|
'count' = 1
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$InternalCount = 0;
|
||||||
|
$UseInterface = '';
|
||||||
|
foreach ($interface in $ExternalInterfaces.Keys) {
|
||||||
|
$currentCount = $ExternalInterfaces[$interface].count;
|
||||||
|
if ($currentCount -gt $InternalCount) {
|
||||||
|
$InternalCount = $currentCount;
|
||||||
|
$UseInterface = $interface;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $UseInterface;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
function Get-IcingaServices()
|
function Get-IcingaServices()
|
||||||
{
|
{
|
||||||
param (
|
param (
|
||||||
[array]$Service
|
[array]$Service,
|
||||||
|
[array]$Exclude = @()
|
||||||
);
|
);
|
||||||
|
|
||||||
$ServiceInformation = Get-Service -Name $Service -ErrorAction SilentlyContinue;
|
$ServiceInformation = Get-Service -Name $Service -ErrorAction SilentlyContinue;
|
||||||
|
|
@ -23,11 +24,17 @@ function Get-IcingaServices()
|
||||||
|
|
||||||
[array]$DependentServices = $null;
|
[array]$DependentServices = $null;
|
||||||
[array]$DependingServices = $null;
|
[array]$DependingServices = $null;
|
||||||
|
$ServiceExitCode = 0;
|
||||||
[string]$ServiceUser = '';
|
[string]$ServiceUser = '';
|
||||||
|
|
||||||
|
if ($Exclude -contains $service.ServiceName) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($wmiService in $ServiceWmiInfo) {
|
foreach ($wmiService in $ServiceWmiInfo) {
|
||||||
if ($wmiService.Name -eq $service.ServiceName) {
|
if ($wmiService.Name -eq $service.ServiceName) {
|
||||||
$ServiceUser = $wmiService.StartName;
|
$ServiceUser = $wmiService.StartName;
|
||||||
|
$ServiceExitCode = $wmiService.ExitCode;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -77,6 +84,7 @@ function Get-IcingaServices()
|
||||||
'value' = $service.StartType;
|
'value' = $service.StartType;
|
||||||
};
|
};
|
||||||
'ServiceUser' = $ServiceUser;
|
'ServiceUser' = $ServiceUser;
|
||||||
|
'ExitCode' = $ServiceExitCode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
||||||
21
lib/core/tools/Get-UnitPrefixIEC.psm1
Normal file
21
lib/core/tools/Get-UnitPrefixIEC.psm1
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
function Get-UnitPrefixIEC()
|
||||||
|
{
|
||||||
|
param(
|
||||||
|
[single]$Value
|
||||||
|
);
|
||||||
|
|
||||||
|
If ( $Value / [math]::Pow(2, 50) -ge 1 ) {
|
||||||
|
return 'PiB'
|
||||||
|
} elseif ( $Value / [math]::Pow(2, 40) -ge 1 ) {
|
||||||
|
return 'TiB'
|
||||||
|
} elseif ( $Value / [math]::Pow(2, 30) -ge 1 ) {
|
||||||
|
return 'GiB'
|
||||||
|
} elseif ( $Value / [math]::Pow(2, 20) -ge 1 ) {
|
||||||
|
return 'MiB'
|
||||||
|
} elseif ( $Value / [math]::Pow(2, 10) -ge 1 ) {
|
||||||
|
return 'KiB'
|
||||||
|
} else {
|
||||||
|
return 'B'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
20
lib/core/tools/Get-UnitPrefixSI.psm1
Normal file
20
lib/core/tools/Get-UnitPrefixSI.psm1
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
function Get-UnitPrefixSI()
|
||||||
|
{
|
||||||
|
param(
|
||||||
|
[single]$Value
|
||||||
|
);
|
||||||
|
|
||||||
|
If ( $Value / [math]::Pow(10, 15) -ge 1 ) {
|
||||||
|
return 'PB'
|
||||||
|
} elseif ( $Value / [math]::Pow(10, 12) -ge 1 ) {
|
||||||
|
return 'TB'
|
||||||
|
} elseif ( $Value / [math]::Pow(10, 9) -ge 1 ) {
|
||||||
|
return 'GB'
|
||||||
|
} elseif ( $Value / [math]::Pow(10, 6) -ge 1 ) {
|
||||||
|
return 'MB'
|
||||||
|
} elseif ( $Value / [math]::Pow(10, 3) -ge 1 ) {
|
||||||
|
return 'KB'
|
||||||
|
} else {
|
||||||
|
return 'B'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -24,10 +24,10 @@
|
||||||
'us' = 'microseconds';
|
'us' = 'microseconds';
|
||||||
'%' = 'percent';
|
'%' = 'percent';
|
||||||
'B' = 'bytes';
|
'B' = 'bytes';
|
||||||
'KB' = 'kilobytes';
|
'KB' = 'Kilobytes';
|
||||||
'MB' = 'megabytes';
|
'MB' = 'Megabytes';
|
||||||
'GB' = 'gigabytes';
|
'GB' = 'Gigabytes';
|
||||||
'TB' = 'terabytes';
|
'TB' = 'Terabytes';
|
||||||
'c' = 'counter';
|
'c' = 'counter';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@
|
||||||
PerformanceCounter = 'A plugin failed to fetch Performance Counter information. Please ensure the counter is written properly and available on your system.';
|
PerformanceCounter = 'A plugin failed to fetch Performance Counter information. Please ensure the counter is written properly and available on your system.';
|
||||||
EventLogLogName = 'Failed to fetch EventLog information. Please specify a valid LogName.';
|
EventLogLogName = 'Failed to fetch EventLog information. Please specify a valid LogName.';
|
||||||
EventLog = 'Failed to fetch EventLog information. Please check your inputs for EntryTypes and other categories and try again.';
|
EventLog = 'Failed to fetch EventLog information. Please check your inputs for EntryTypes and other categories and try again.';
|
||||||
|
ConversionUnitMissing = 'Unable to parse input value. You have to add an unit to your input value. Example: "10GB". Allowed units are: "B, KB, MB, GB, TB, PB, KiB, MiB, GiB, TiB, PiB".';
|
||||||
};
|
};
|
||||||
|
|
||||||
<#
|
<#
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue