From c6e40b18a6c3feb31466ea834a4259ef6e12e7ef Mon Sep 17 00:00:00 2001 From: Crited Date: Fri, 26 Jul 2019 13:01:51 +0200 Subject: [PATCH] Added IcingaCheckUsers and Libraray for users --- lib/plugins/Invoke-IcingaCheckUsers.psm1 | 26 ++++++++++++++++++++++++ lib/provider/users/Get-IcingaUsers.psm1 | 18 ++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 lib/provider/users/Get-IcingaUsers.psm1 diff --git a/lib/plugins/Invoke-IcingaCheckUsers.psm1 b/lib/plugins/Invoke-IcingaCheckUsers.psm1 index fd2a3e3..0a87ebe 100644 --- a/lib/plugins/Invoke-IcingaCheckUsers.psm1 +++ b/lib/plugins/Invoke-IcingaCheckUsers.psm1 @@ -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); } \ No newline at end of file diff --git a/lib/provider/users/Get-IcingaUsers.psm1 b/lib/provider/users/Get-IcingaUsers.psm1 new file mode 100644 index 0000000..366e974 --- /dev/null +++ b/lib/provider/users/Get-IcingaUsers.psm1 @@ -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; +} \ No newline at end of file