Added IcingaCheckUsers and Libraray for users

This commit is contained in:
Crited 2019-07-26 13:01:51 +02:00
parent 26d0887ae9
commit c6e40b18a6
2 changed files with 44 additions and 0 deletions

View file

@ -1,4 +1,30 @@
Import-IcingaLib icinga\plugin;
Import-IcingaLib provider\users;
function Invoke-IcingaCheckUsers()
{
param (
[array]$username,
[switch]$NoPerfData,
$Verbose
);
$UsersPackage = New-IcingaCheckPackage -Name 'Users' -OperatorAnd -Verbos $Verbose;
$UserInformation = Get-IcingaUsers -Username $username;
foreach ($ExistingUser in $UserInformation) {
Write-Host $ExistingUser;
If ($null -eq $ExistingUser)
{
continue;
}
$Status = $ExistingUser.Enabled;
$IcingaCheck = New-IcingaCheck -Name ([string]::Format('User {0} Status {1} ', $ExistingUser, $Status)) -Value $Status -NoPerfData;
$IcingaCheck.CritIfNotMatch('True') | Out-Null;
$UsersPackage.AddCheck($IcingaCheck);
}
exit (New-IcingaCheckResult -Name 'Users' -Check $UsersPackage -NoPerfData $NoPerfData -Compile);
}

View file

@ -0,0 +1,18 @@
function Get-IcingaUsers ()
{
param (
[array]$Username
);
if ($null -eq $Username) {
return Get-LocalUser;
} else {
[array]$UserInformation
foreach ($UniqueUser in $Username) {
[array]$UserInformation += Get-LocalUser -Name $UniqueUser;
}
}
return $UserInformation;
}