mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-21 07:10:15 -05:00
Added IcingaCheckUsers and Libraray for users
This commit is contained in:
parent
26d0887ae9
commit
c6e40b18a6
2 changed files with 44 additions and 0 deletions
|
|
@ -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);
|
||||
}
|
||||
18
lib/provider/users/Get-IcingaUsers.psm1
Normal file
18
lib/provider/users/Get-IcingaUsers.psm1
Normal 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;
|
||||
}
|
||||
Loading…
Reference in a new issue