-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMrANagios.psm1
44 lines (36 loc) · 1.54 KB
/
MrANagios.psm1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# MrANagios Script Module
# Set default parameter values using global scope
# Change these values to match your environment.
$Global:PSDefaultParameterValues["*:NagiosXiApiUrl"]="https://nagiosxi.domain.com/nagiosxi/api/v1/"
$Global:PSDefaultParameterValues["*:NagiosXiApiKey"]="PutYourAPIKeyHere"
$Global:PSDefaultParameterValues["*:NagiosCoreUrl"]='https://nagiosxi.domain.com/nagios'
# Optionally read nagios credentials from CliXml file on disk.
#requires -Modules MrACredential
$NagiosCredentialFile = 'C:\Credentials\NagiosLogon.xml'
$NagiosCredentialKey = 'C:\Keys\NagiosLogon.key'
if ((Test-Path $NagiosCredentialFile) -and (Test-Path $NagiosCredentialKey)) {
Write-Verbose "Nagios credential file and key exists. Importing credential from file."
$Credential = Import-Credential -CredentialFilePath $NagiosCredentialFile -EncryptionKeyPath $NagiosCredentialKey
$Global:PSDefaultParameterValues['*Nagios*:Credential']=$Credential
}
else {
Write-Verbose 'No credential file found.'
$Global:PSDefaultParameterValues["*:username"]=$env:USERNAME
}
# Source all ps1 files from module directory.
# https://becomelotr.wordpress.com/2017/02/13/expensive-dot-sourcing/
foreach ($file in Get-ChildItem $PSScriptRoot\*.ps1) {
$ExecutionContext.InvokeCommand.InvokeScript(
$false,
(
[scriptblock]::Create(
[io.file]::ReadAllText(
$file.FullName,
[Text.Encoding]::UTF8
)
)
),
$null,
$null
)
}