From ddba722ab618404abd689ce71d305de6755dae87 Mon Sep 17 00:00:00 2001 From: Alexander Stoll Date: Mon, 22 Jul 2019 10:01:11 +0200 Subject: [PATCH] Structure Change; Added Updates -> hotfix, pending, installing --- .../Icinga_ProviderBios.psm1} | 82 ++++++------ lib/provider/bios/Show-IcingaBiosData.psm1 | 13 ++ .../{cpu.psm1 => cpu/Icinga_ProviderCpu.psm1} | 28 +--- lib/provider/cpu/Show-IcingaCPUData.psm1 | 16 +++ .../Icinga_ProviderDisks.psm1} | 121 ------------------ lib/provider/disks/Show-IcingaDiskData.psm1 | 67 ++++++++++ .../Icinga_ProviderEnums.psm1} | 0 .../Icinga_ProviderMemory.psm1} | 62 +-------- .../memory/Show-IcingaMemoryData.psm1 | 52 ++++++++ .../Icinga_ProviderProcess.psm1} | 29 ----- .../Icinga_ProviderServices.psm1} | 0 .../updates/Get-IcingaUpdatesHotfix.psm1 | 29 +++++ .../updates/Get-IcingaUpdatesInstalled.psm1 | 75 +++++++++++ .../updates/Get-IcingaUpdatesPending.psm1 | 78 +++++++++++ .../windows/Icinga_ProviderWindows.psm1 | 11 ++ 15 files changed, 386 insertions(+), 277 deletions(-) rename lib/provider/{bios.psm1 => bios/Icinga_ProviderBios.psm1} (77%) create mode 100644 lib/provider/bios/Show-IcingaBiosData.psm1 rename lib/provider/{cpu.psm1 => cpu/Icinga_ProviderCpu.psm1} (89%) create mode 100644 lib/provider/cpu/Show-IcingaCPUData.psm1 rename lib/provider/{disks.psm1 => disks/Icinga_ProviderDisks.psm1} (50%) create mode 100644 lib/provider/disks/Show-IcingaDiskData.psm1 rename lib/provider/{enums.psm1 => enums/Icinga_ProviderEnums.psm1} (100%) rename lib/provider/{memory.psm1 => memory/Icinga_ProviderMemory.psm1} (63%) create mode 100644 lib/provider/memory/Show-IcingaMemoryData.psm1 rename lib/provider/{process.psm1 => process/Icinga_ProviderProcess.psm1} (81%) rename lib/provider/{services.psm1 => services/Icinga_ProviderServices.psm1} (100%) create mode 100644 lib/provider/updates/Get-IcingaUpdatesHotfix.psm1 create mode 100644 lib/provider/updates/Get-IcingaUpdatesInstalled.psm1 create mode 100644 lib/provider/updates/Get-IcingaUpdatesPending.psm1 create mode 100644 lib/provider/windows/Icinga_ProviderWindows.psm1 diff --git a/lib/provider/bios.psm1 b/lib/provider/bios/Icinga_ProviderBios.psm1 similarity index 77% rename from lib/provider/bios.psm1 rename to lib/provider/bios/Icinga_ProviderBios.psm1 index e2acd7f..41eeb87 100644 --- a/lib/provider/bios.psm1 +++ b/lib/provider/bios/Icinga_ProviderBios.psm1 @@ -1,25 +1,4 @@ Import-Module $IncludeDir\provider\enums; - -<################################################################################################## -################# Runspace "Show-Icinga{BIOS}" #################################################### -##################################################################################################> -function Show-IcingaBiosData() -{ - $BIOSInformation = Get-CimInstance Win32_BIOS; - [hashtable]$BIOSData = @{}; - - foreach ($bios_properties in $BIOSInformation) { - foreach($bios in $bios_properties.CimInstanceProperties) { - $BIOSData.Add($bios.Name, $bios.Value); - } - } - - return $BIOSData; -} - -<################################################################################################## -################# Runspace "Get-Icinga{BIOS}" ##################################################### -##################################################################################################> function Get-IcingaBios() { <# Collects the most important BIOS informations, @@ -51,6 +30,45 @@ function Get-IcingaBios() return $BIOSData; } + +function Get-IcingaBiosCharacteristics() +{ + param([switch]$Sorted); + + $bios = Get-CimInstance WIN32_BIOS; + [hashtable]$BIOSCharacteristics = @{}; + + foreach ($id in $bios.BiosCharacteristics) { + $BIOSCharacteristics.Add([string]$id, $ProviderEnums.BiosCharacteristics.Item([int]$id)); + } + + $output = $BIOSCharacteristics; + + if ($sorted) { + $output = $BIOSCharacteristics.GetEnumerator() | Sort-Object name; + } + + return @{'value' = $output; 'name' = 'BiosCharacteristics'}; +} +function Get-IcingaBiosCharacteristics() +{ + param([switch]$Sorted); + + $bios = Get-CimInstance WIN32_BIOS; + [hashtable]$BIOSCharacteristics = @{}; + + foreach ($id in $bios.BiosCharacteristics) { + $BIOSCharacteristics.Add([string]$id, $ProviderEnums.BiosCharacteristics.Item([int]$id)); + } + + $output = $BIOSCharacteristics; + + if ($sorted) { + $output = $BIOSCharacteristics.GetEnumerator() | Sort-Object name; + } + + return @{'value' = $output; 'name' = 'BiosCharacteristics'}; +} function Get-IcingaBiosSerialNumber() { $bios = Get-CimInstance Win32_BIOS; @@ -104,24 +122,4 @@ function Get-IcingaBiosSoftwareElementID() { $bios = Get-CimInstance Win32_BIOS; return @{'value' = $bios.SoftwareElementID; 'name' = 'SoftwareElementID'}; -} - -function Get-IcingaBiosCharacteristics() -{ - param([switch]$Sorted); - - $bios = Get-CimInstance WIN32_BIOS; - [hashtable]$BIOSCharacteristics = @{}; - - foreach ($id in $bios.BiosCharacteristics) { - $BIOSCharacteristics.Add([string]$id, $ProviderEnums.BiosCharacteristics.Item([int]$id)); - } - - $output = $BIOSCharacteristics; - - if ($sorted) { - $output = $BIOSCharacteristics.GetEnumerator() | Sort-Object name; - } - - return @{'value' = $output; 'name' = 'BiosCharacteristics'}; -} +} \ No newline at end of file diff --git a/lib/provider/bios/Show-IcingaBiosData.psm1 b/lib/provider/bios/Show-IcingaBiosData.psm1 new file mode 100644 index 0000000..087c461 --- /dev/null +++ b/lib/provider/bios/Show-IcingaBiosData.psm1 @@ -0,0 +1,13 @@ +function Show-IcingaBiosData() +{ + $BIOSInformation = Get-CimInstance Win32_BIOS; + [hashtable]$BIOSData = @{}; + + foreach ($bios_properties in $BIOSInformation) { + foreach($bios in $bios_properties.CimInstanceProperties) { + $BIOSData.Add($bios.Name, $bios.Value); + } + } + + return $BIOSData; +} \ No newline at end of file diff --git a/lib/provider/cpu.psm1 b/lib/provider/cpu/Icinga_ProviderCpu.psm1 similarity index 89% rename from lib/provider/cpu.psm1 rename to lib/provider/cpu/Icinga_ProviderCpu.psm1 index 986a9f9..9324ba8 100644 --- a/lib/provider/cpu.psm1 +++ b/lib/provider/cpu/Icinga_ProviderCpu.psm1 @@ -1,28 +1,4 @@ Import-Module $IncludeDir\provider\enums; - -<################################################################################################## -################# Runspace "Show-Icinga{CPU}" ##################################################### -##################################################################################################> -function Show-IcingaCPUData() -{ - -$CPUInformation = Get-CimInstance Win32_Processor; -[hashtable]$PhysicalCPUData = @{}; - -foreach ($cpu_properties in $CPUInformation) { - $cpu_datails = @{}; - foreach($cpu_core in $cpu_properties.CimInstanceProperties) { - $cpu_datails.Add($cpu_core.Name, $cpu_core.Value); - } - $PhysicalCPUData.Add($cpu_datails.DeviceID, $cpu_datails); -} - -return $PhysicalCPUData; -} - -<################################################################################################## -################# Runspace "Get-Icinga{Memory}" ################################################### -##################################################################################################> function Get-IcingaCPUs() { <# Collects the most important CPU informations, @@ -284,8 +260,8 @@ function Get-IcingaCPUNumberOfLogicalProcessors() function Get-IcingaCPUCount() { - <# Collects the most important CPU informations, - e.g. name, version, manufacturer#> + <# Compares whether NumberofLogicalCores, NumberofCores or Threadcount across all CPUs is the highest, + this function is used in provider/memory/Icinga_ProviderMemory.psm1#> $CPUInformation = Get-CimInstance Win32_Processor; foreach ($cpu in $CPUInformation) { diff --git a/lib/provider/cpu/Show-IcingaCPUData.psm1 b/lib/provider/cpu/Show-IcingaCPUData.psm1 new file mode 100644 index 0000000..651a595 --- /dev/null +++ b/lib/provider/cpu/Show-IcingaCPUData.psm1 @@ -0,0 +1,16 @@ +function Show-IcingaCPUData() +{ + +$CPUInformation = Get-CimInstance Win32_Processor; +[hashtable]$PhysicalCPUData = @{}; + +foreach ($cpu_properties in $CPUInformation) { + $cpu_datails = @{}; + foreach($cpu_core in $cpu_properties.CimInstanceProperties) { + $cpu_datails.Add($cpu_core.Name, $cpu_core.Value); + } + $PhysicalCPUData.Add($cpu_datails.DeviceID, $cpu_datails); +} + +return $PhysicalCPUData; +} \ No newline at end of file diff --git a/lib/provider/disks.psm1 b/lib/provider/disks/Icinga_ProviderDisks.psm1 similarity index 50% rename from lib/provider/disks.psm1 rename to lib/provider/disks/Icinga_ProviderDisks.psm1 index eed30ec..74dab9e 100644 --- a/lib/provider/disks.psm1 +++ b/lib/provider/disks/Icinga_ProviderDisks.psm1 @@ -1,99 +1,5 @@ Import-Module $IncludeDir\provider\enums; -<################################################################################################## -################# Runspace "Show-Icinga{Disk}" #################################################### -##################################################################################################> - -function Show-IcingaDiskData { - - $DisksInformations = Get-CimInstance Win32_DiskDrive; - - [hashtable]$PhysicalDiskData = @{}; - - foreach ($disk_properties in $DisksInformations) { - $disk_datails = @{}; - foreach($disk in $disk_properties.CimInstanceProperties) { - $disk_datails.Add($disk.Name, $disk.Value); - } - $disk_datails.Add('DriveReference', @()); - $PhysicalDiskData.Add($disk_datails.DeviceID, $disk_datails); - } - - $DiskPartitionInfo = Get-WmiObject Win32_DiskDriveToDiskPartition; - - [hashtable]$MapDiskPartitionToLogicalDisk = @{}; - - foreach ($item in $DiskPartitionInfo) { - [string]$diskPartition = $item.Dependent.SubString( - $item.Dependent.LastIndexOf('=') + 1, - $item.Dependent.Length - $item.Dependent.LastIndexOf('=') - 1 - ); - $diskPartition = $diskPartition.Replace('"', ''); - - [string]$physicalDrive = $item.Antecedent.SubString( - $item.Antecedent.LastIndexOf('\') + 1, - $item.Antecedent.Length - $item.Antecedent.LastIndexOf('\') - 1 - ) - $physicalDrive = $physicalDrive.Replace('"', ''); - - $MapDiskPartitionToLogicalDisk.Add($diskPartition, $physicalDrive); - } - - $LogicalDiskInfo = Get-WmiObject Win32_LogicalDiskToPartition; - - foreach ($item in $LogicalDiskInfo) { - [string]$driveLetter = $item.Dependent.SubString( - $item.Dependent.LastIndexOf('=') + 1, - $item.Dependent.Length - $item.Dependent.LastIndexOf('=') - 1 - ); - $driveLetter = $driveLetter.Replace('"', ''); - - [string]$diskPartition = $item.Antecedent.SubString( - $item.Antecedent.LastIndexOf('=') + 1, - $item.Antecedent.Length - $item.Antecedent.LastIndexOf('=') - 1 - ) - $diskPartition = $diskPartition.Replace('"', ''); - - if ($MapDiskPartitionToLogicalDisk.ContainsKey($diskPartition)) { - foreach ($disk in $PhysicalDiskData.Keys) { - [string]$DiskId = $disk.SubString( - $disk.LastIndexOf('\') + 1, - $disk.Length - $disk.LastIndexOf('\') - 1 - ); - - if ($DiskId.ToLower() -eq $MapDiskPartitionToLogicalDisk[$diskPartition].ToLower()) { - $PhysicalDiskData[$disk]['DriveReference'] += $driveLetter; - } - } - } - } - - return $PhysicalDiskData; - -} - -function Show-IcingaDiskPhysical() -{ - $DisksInformations = Get-CimInstance Win32_DiskDrive; - - [hashtable]$PhysicalDiskData = @{}; - - foreach ($disk_properties in $DisksInformations) { - $disk_datails = @{}; - foreach($disk in $disk_properties.CimInstanceProperties) { - $disk_datails.Add($disk.Name, $disk.Value); - } - $disk_datails.Add('DriveReference', @()); - $PhysicalDiskData.Add($disk_datails.DeviceID, $disk_datails); - } - - return $PhysicalDiskData; -} - -<################################################################################################## -################# Runspace "Get-Icinga{Disk}" #################################################### -##################################################################################################> - function Get-IcingaDiskInformation() { <# Fetches the information for other more specific Get-IcingaDisk-functions @@ -160,33 +66,6 @@ function Get-IcingaDiskPartitions() return $PartitionDiskByDriveLetter; } -#Code-Snippen that still exists for LordHepipud's amusement -function Get-IcingaDiskPartitionSize() -{ - param([switch]$sorted); - - [hashtable]$PartitionSizeByDriveLetter = @{}; - - # Should be dependent on the driveLetters returned in: "Show-IcingaDiskData" - for ($test = 0; $test -lt 26; $test++) - { - $DiskDriveLetter = ([char](65 + $test)) - $PartitionSize = (Get-Partition -DriveLetter $DiskDriveLetter -ErrorAction 'silentlycontinue').Size; - if ($null -eq $PartitionSize) - { - $PartitionSize = "0"; - } - $PartitionSizeByDriveLetter.Add("$DiskDriveLetter", $PartitionSize); - } - - $output = $PartitionSizeByDriveLetter; - - if ($sorted) { - $output = $PartitionSizeByDriveLetter.GetEnumerator() | Sort-Object name; - } - - return @{'value' = $output; 'name' = 'Size'}; -} function Get-IcingaDiskCapabilities { $DiskInformation = Get-CimInstance Win32_DiskDrive; diff --git a/lib/provider/disks/Show-IcingaDiskData.psm1 b/lib/provider/disks/Show-IcingaDiskData.psm1 new file mode 100644 index 0000000..fab6e5b --- /dev/null +++ b/lib/provider/disks/Show-IcingaDiskData.psm1 @@ -0,0 +1,67 @@ +function Show-IcingaDiskData { + + $DisksInformations = Get-CimInstance Win32_DiskDrive; + + [hashtable]$PhysicalDiskData = @{}; + + foreach ($disk_properties in $DisksInformations) { + $disk_datails = @{}; + foreach($disk in $disk_properties.CimInstanceProperties) { + $disk_datails.Add($disk.Name, $disk.Value); + } + $disk_datails.Add('DriveReference', @()); + $PhysicalDiskData.Add($disk_datails.DeviceID, $disk_datails); + } + + $DiskPartitionInfo = Get-WmiObject Win32_DiskDriveToDiskPartition; + + [hashtable]$MapDiskPartitionToLogicalDisk = @{}; + + foreach ($item in $DiskPartitionInfo) { + [string]$diskPartition = $item.Dependent.SubString( + $item.Dependent.LastIndexOf('=') + 1, + $item.Dependent.Length - $item.Dependent.LastIndexOf('=') - 1 + ); + $diskPartition = $diskPartition.Replace('"', ''); + + [string]$physicalDrive = $item.Antecedent.SubString( + $item.Antecedent.LastIndexOf('\') + 1, + $item.Antecedent.Length - $item.Antecedent.LastIndexOf('\') - 1 + ) + $physicalDrive = $physicalDrive.Replace('"', ''); + + $MapDiskPartitionToLogicalDisk.Add($diskPartition, $physicalDrive); + } + + $LogicalDiskInfo = Get-WmiObject Win32_LogicalDiskToPartition; + + foreach ($item in $LogicalDiskInfo) { + [string]$driveLetter = $item.Dependent.SubString( + $item.Dependent.LastIndexOf('=') + 1, + $item.Dependent.Length - $item.Dependent.LastIndexOf('=') - 1 + ); + $driveLetter = $driveLetter.Replace('"', ''); + + [string]$diskPartition = $item.Antecedent.SubString( + $item.Antecedent.LastIndexOf('=') + 1, + $item.Antecedent.Length - $item.Antecedent.LastIndexOf('=') - 1 + ) + $diskPartition = $diskPartition.Replace('"', ''); + + if ($MapDiskPartitionToLogicalDisk.ContainsKey($diskPartition)) { + foreach ($disk in $PhysicalDiskData.Keys) { + [string]$DiskId = $disk.SubString( + $disk.LastIndexOf('\') + 1, + $disk.Length - $disk.LastIndexOf('\') - 1 + ); + + if ($DiskId.ToLower() -eq $MapDiskPartitionToLogicalDisk[$diskPartition].ToLower()) { + $PhysicalDiskData[$disk]['DriveReference'] += $driveLetter; + } + } + } + } + + return $PhysicalDiskData; + +} \ No newline at end of file diff --git a/lib/provider/enums.psm1 b/lib/provider/enums/Icinga_ProviderEnums.psm1 similarity index 100% rename from lib/provider/enums.psm1 rename to lib/provider/enums/Icinga_ProviderEnums.psm1 diff --git a/lib/provider/memory.psm1 b/lib/provider/memory/Icinga_ProviderMemory.psm1 similarity index 63% rename from lib/provider/memory.psm1 rename to lib/provider/memory/Icinga_ProviderMemory.psm1 index 6e17fc0..2631ae6 100644 --- a/lib/provider/memory.psm1 +++ b/lib/provider/memory/Icinga_ProviderMemory.psm1 @@ -1,63 +1,4 @@ Import-Module $IncludeDir\provider\enums; - -<################################################################################################## -################# Runspace "Show-Icinga{Memory}" ################################################## -##################################################################################################> -function Show-IcingaMemoryData () -{ - - $MEMInformation = Get-CimInstance Win32_PhysicalMemory; - - [hashtable]$MEMData = @{}; - - foreach($memory in $MEMInformation) { - $MEMData.Add( - $memory.tag.trim("Physical Memory"), @{ - 'Caption' = $memory.Name; - 'Description' = $memory.Description; - 'Name' = $memory.Name; - 'InstallDate' = $memory.InstallDate; - 'Status' = $memory.Status - 'CreationClassName'= $memory.CreationClassName - 'Manufacturer'= $memory.Manufacturer - 'Model'= $memory.Model - 'OtherIdentifyingInfo'= $memory.OtherIdentifyingInfo - 'PartNumber'= $memory.PartNumber - 'PoweredOn'= $memory.PoweredOn - 'SerialNumber'= $memory.SerialNumber - 'SKU'= $memory.SKU - 'Tag'= $memory.Tag - 'Version'= $memory.Version - 'HotSwappable'= $memory.HotSwappable - 'Removable'= $memory.Removable - 'Replaceable'= $memory.Replaceable - 'FormFactor'= $memory.FormFactor - 'BankLabel'= $memory.BankLabel - 'Capacity'= $memory.Capacity - 'DataWidth'= $memory.DataWidth - 'InterleavePosition'= $memory.InterleavePosition - 'MemoryType'= $memory.MemoryType - 'PositionInRow'= $memory.PositionInRow - 'Speed'= $memory.Speed - 'TotalWidth'= $memory.TotalWidth - 'Attributes'= $memory.Attributes - 'ConfiguredClockSpeed'= $memory.ConfiguredClockSpeed - 'ConfiguredVoltage'= $memory.ConfiguredVoltage - 'DeviceLocator'= $memory.DeviceLocator - 'InterleaveDataDepth'= $memory.InterleaveDataDepth - 'MaxVoltage'= $memory.MaxVoltage - 'MinVoltage'= $memory.MinVoltage - 'SMBIOSMemoryType'= $memory.SMBIOSMemoryType - 'TypeDetail'= $memory.TypeDetail - 'PSComputerName'= $memory.PSComputerName - } - ); - } - return $MEMData; -} -<################################################################################################## -################# Runspace "Get-Icinga{Memory}" ################################################### -##################################################################################################> function Get-IcingaMemory () { <# Collects the most important Memory informations, @@ -127,6 +68,9 @@ function Get-IcingaMemory () function Get-IcingaMemoryInformation() { + <# Fetches the information for other more specific Get-IcingaMemory-functions + e.g. Get-IcingaMemoryMaxVoltage; Get-IcingaMemoryTotalWidth. + Can be used to fetch information regarding a value of your choice. #> param( [string]$Parameter ); diff --git a/lib/provider/memory/Show-IcingaMemoryData.psm1 b/lib/provider/memory/Show-IcingaMemoryData.psm1 new file mode 100644 index 0000000..7bf8e5f --- /dev/null +++ b/lib/provider/memory/Show-IcingaMemoryData.psm1 @@ -0,0 +1,52 @@ +function Show-IcingaMemoryData () +{ + + $MEMInformation = Get-CimInstance Win32_PhysicalMemory; + + [hashtable]$MEMData = @{}; + + foreach($memory in $MEMInformation) { + $MEMData.Add( + $memory.tag.trim("Physical Memory"), @{ + 'Caption' = $memory.Name; + 'Description' = $memory.Description; + 'Name' = $memory.Name; + 'InstallDate' = $memory.InstallDate; + 'Status' = $memory.Status + 'CreationClassName'= $memory.CreationClassName + 'Manufacturer'= $memory.Manufacturer + 'Model'= $memory.Model + 'OtherIdentifyingInfo'= $memory.OtherIdentifyingInfo + 'PartNumber'= $memory.PartNumber + 'PoweredOn'= $memory.PoweredOn + 'SerialNumber'= $memory.SerialNumber + 'SKU'= $memory.SKU + 'Tag'= $memory.Tag + 'Version'= $memory.Version + 'HotSwappable'= $memory.HotSwappable + 'Removable'= $memory.Removable + 'Replaceable'= $memory.Replaceable + 'FormFactor'= $memory.FormFactor + 'BankLabel'= $memory.BankLabel + 'Capacity'= $memory.Capacity + 'DataWidth'= $memory.DataWidth + 'InterleavePosition'= $memory.InterleavePosition + 'MemoryType'= $memory.MemoryType + 'PositionInRow'= $memory.PositionInRow + 'Speed'= $memory.Speed + 'TotalWidth'= $memory.TotalWidth + 'Attributes'= $memory.Attributes + 'ConfiguredClockSpeed'= $memory.ConfiguredClockSpeed + 'ConfiguredVoltage'= $memory.ConfiguredVoltage + 'DeviceLocator'= $memory.DeviceLocator + 'InterleaveDataDepth'= $memory.InterleaveDataDepth + 'MaxVoltage'= $memory.MaxVoltage + 'MinVoltage'= $memory.MinVoltage + 'SMBIOSMemoryType'= $memory.SMBIOSMemoryType + 'TypeDetail'= $memory.TypeDetail + 'PSComputerName'= $memory.PSComputerName + } + ); + } + return $MEMData; +} \ No newline at end of file diff --git a/lib/provider/process.psm1 b/lib/provider/process/Icinga_ProviderProcess.psm1 similarity index 81% rename from lib/provider/process.psm1 rename to lib/provider/process/Icinga_ProviderProcess.psm1 index 26e639f..729138b 100644 --- a/lib/provider/process.psm1 +++ b/lib/provider/process/Icinga_ProviderProcess.psm1 @@ -23,7 +23,6 @@ function Get-IcingaProcessData { [hashtable]$ProcessList = @{}; [hashtable]$ProcessNamesUnique = @{}; [hashtable]$ProcessIDsByName = @{}; - #$NumberOfCPUThreads = $Icinga2.System.NumberOfCPUThreads; foreach ($process in $ProcessInformation) { [string]$processName = $process.Name.Replace('.exe', ''); @@ -92,33 +91,5 @@ function Get-IcingaProcessData { $ProcessData.Add('Process Count', $ProcessInformation.Count); $ProcessData.add('Processes', $ProcessList); - return $ProcessData; - # Code Stolli below - - foreach ($NameID in $ProcessUniqueList.Name) { - $ProcessIDsBasedOnName = (Get-WmiObject Win32_Process -Filter name="'${NameID}'").ProcessID; - $ProcessIDsByName.Add($NameID,$ProcessIDsBasedOnName); - } - - foreach ($id in $ProcessUniqueList) { - $nameid = $id.name; - $ProcessNamesUnique.Add( - $id.Name.trim(".exe"), @{ - 'processlist' = @{ - $ProcessIDsByName.Item("$nameid") = "metadata"; - }; - 'perfdata' = @{ - 'lawl' = 'lol'; - 'lel' = 'lel'; - 'lol' = 'eyooo'; - } - } - ); - } - - - $ProcessData.Add('Process Count', $ProcessInformation.Count); - $ProcessData.add('Processes', $ProcessNamesUnique); - return $ProcessData; } \ No newline at end of file diff --git a/lib/provider/services.psm1 b/lib/provider/services/Icinga_ProviderServices.psm1 similarity index 100% rename from lib/provider/services.psm1 rename to lib/provider/services/Icinga_ProviderServices.psm1 diff --git a/lib/provider/updates/Get-IcingaUpdatesHotfix.psm1 b/lib/provider/updates/Get-IcingaUpdatesHotfix.psm1 new file mode 100644 index 0000000..2f62185 --- /dev/null +++ b/lib/provider/updates/Get-IcingaUpdatesHotfix.psm1 @@ -0,0 +1,29 @@ +function Get-IcingaUpdatesHotfix (){ + +[hashtable]$HotfixInfo = @{}; +[hashtable]$HotfixNameCache = @{}; + +# First fetch all of our hotfixes +$Hotfixes = Get-Hotfix; + +foreach ($property in $Hotfixes) { + [hashtable]$HotfixData = @{}; + foreach ($hotfix in $property.Properties) { + $HotfixData.Add($hotfix.Name, $hotfix.Value); + } + + [string]$name = [string]::Format('{0} [{1}]', $HotfixData.HotFixID, $HotfixData.InstalledOn); + + if ($HotfixNameCache.ContainsKey($name) -eq $FALSE) { + $HotfixNameCache.Add($name, 1); + } else { + $HotfixNameCache[$name] += 1; + $name = [string]::Format('{0} ({1})', $name, $HotfixNameCache[$name]); + } + + $HotfixInfo.Add($name, $HotfixData); +} + +return $HotfixInfo; + +} \ No newline at end of file diff --git a/lib/provider/updates/Get-IcingaUpdatesInstalled.psm1 b/lib/provider/updates/Get-IcingaUpdatesInstalled.psm1 new file mode 100644 index 0000000..a294303 --- /dev/null +++ b/lib/provider/updates/Get-IcingaUpdatesInstalled.psm1 @@ -0,0 +1,75 @@ +function Get-IcingaUpdatesInstalled () +{ + +# Fetch all informations about installed updates and add them +$WindowsUpdates = New-Object -ComObject "Microsoft.Update.Session"; +$SearchIndex = $WindowsUpdates.CreateUpdateSearcher(); +[hashtable]$UpdateList = @{}; +[hashtable]$UpdateInstalled = @{}; +[hashtable]$UpdateUninstalled = @{}; +[hashtable]$UpdateOther = @{}; + +# Operation ID's +# 1: Installed +# 2: Uninstalled +# 3: Other + +# At first get a list of our Windows Update history +$Updates = $SearchIndex.QueryHistory(0, $SearchIndex.GetTotalHistoryCount()) | + Select-Object Operation, ResultCode, HResult, Date, Title, Description, ServiceID, SupportUrl; + +foreach ($update in $Updates) { + [string]$UpdateKey = [string]::Format('{0} [{1}|{2}]', $update.Title, $update.Date, $update.HResult); + switch ($update.Operation) { + 1 { + if ($UpdateInstalled.ContainsKey($UpdateKey) -eq $FALSE) { + $UpdateInstalled.Add($UpdateKey, $update); + } else { + $Icinga2.Log.Write( + $Icinga2.Enums.LogState.Warning, + [string]::Format( + 'Unable to add update "{0}" to update list. The key with content "{1}" is already present', + $UpdateKey, + $update + ) + ); + } + }; + 2 { + if ($UpdateUninstalled.ContainsKey($UpdateKey) -eq $FALSE) { + $UpdateUninstalled.Add($UpdateKey, $update); + } else { + $Icinga2.Log.Write( + $Icinga2.Enums.LogState.Warning, + [string]::Format( + 'Unable to add update "{0}" to update list. The key with content "{1}" is already present', + $UpdateKey, + $update + ) + ); + } + }; + default { + if ($UpdateOther.ContainsKey($UpdateKey) -eq $FALSE) { + $UpdateOther.Add($UpdateKey, $update); + } else { + $Icinga2.Log.Write( + $Icinga2.Enums.LogState.Warning, + [string]::Format( + 'Unable to add update "{0}" to update list. The key with content "{1}" is already present', + $UpdateKey, + $update + ) + ); + } + }; + } +} + +$UpdateList.Add('installed', $UpdateInstalled); +$UpdateList.Add('uninstalled', $UpdateUninstalled); +$UpdateList.Add('other', $UpdateOther); + +return $UpdateList; + +} \ No newline at end of file diff --git a/lib/provider/updates/Get-IcingaUpdatesPending.psm1 b/lib/provider/updates/Get-IcingaUpdatesPending.psm1 new file mode 100644 index 0000000..2caa728 --- /dev/null +++ b/lib/provider/updates/Get-IcingaUpdatesPending.psm1 @@ -0,0 +1,78 @@ +function Get-IcingaUpdatesPending () +{ + + [hashtable]$PendingUpdates = @{}; + [hashtable]$PendingUpdateNameCache = @{}; + # Fetch all informations about installed updates and add them + $WindowsUpdates = New-Object -ComObject "Microsoft.Update.Session"; + $SearchIndex = $WindowsUpdates.CreateUpdateSearcher(); + + try { + # Get a list of current pending updates which are not yet installed on the system + $Pending = $SearchIndex.Search("IsInstalled=0"); + $PendingUpdates.Add('count', $Pending.Updates.Count); + + foreach ($update in $Pending.Updates) { + [hashtable]$PendingUpdateDetails = @{}; + $PendingUpdateDetails.Add('Title', $update.Title); + $PendingUpdateDetails.Add('Deadline', $update.Deadline); + $PendingUpdateDetails.Add('Description', $update.Description); + $PendingUpdateDetails.Add('IsBeta', $update.IsBeta); + $PendingUpdateDetails.Add('IsDownloaded', $update.IsDownloaded); + $PendingUpdateDetails.Add('IsHidden', $update.IsHidden); + $PendingUpdateDetails.Add('IsInstalled', $update.IsInstalled); + $PendingUpdateDetails.Add('IsMandatory', $update.IsMandatory); + $PendingUpdateDetails.Add('IsUninstallable', $update.IsUninstallable); + $PendingUpdateDetails.Add('Languages', $update.Languages); + $PendingUpdateDetails.Add('LastDeploymentChangeTime', $update.LastDeploymentChangeTime); + $PendingUpdateDetails.Add('MaxDownloadSize', $update.MaxDownloadSize); + $PendingUpdateDetails.Add('MinDownloadSize', $update.MinDownloadSize); + $PendingUpdateDetails.Add('MoreInfoUrls', $update.MoreInfoUrls); + $PendingUpdateDetails.Add('MsrcSeverity', $update.MsrcSeverity); + $PendingUpdateDetails.Add('RecommendedCpuSpeed', $update.RecommendedCpuSpeed); + $PendingUpdateDetails.Add('RecommendedHardDiskSpace', $update.RecommendedHardDiskSpace); + $PendingUpdateDetails.Add('RecommendedMemory', $update.RecommendedMemory); + $PendingUpdateDetails.Add('ReleaseNotes', $update.ReleaseNotes); + $PendingUpdateDetails.Add('SecurityBulletinIDs', $update.SecurityBulletinIDs); + $PendingUpdateDetails.Add('SupersededUpdateIDs', $update.SupersededUpdateIDs); + $PendingUpdateDetails.Add('SupportUrl', $update.SupportUrl); + $PendingUpdateDetails.Add('Type', $update.Type); + $PendingUpdateDetails.Add('UninstallationNotes', $update.UninstallationNotes); + $PendingUpdateDetails.Add('UninstallationBehavior', $update.UninstallationBehavior); + $PendingUpdateDetails.Add('UninstallationSteps', $update.UninstallationSteps); + $PendingUpdateDetails.Add('KBArticleIDs', $update.KBArticleIDs); + $PendingUpdateDetails.Add('DeploymentAction', $update.DeploymentAction); + $PendingUpdateDetails.Add('DownloadPriority', $update.DownloadPriority); + $PendingUpdateDetails.Add('RebootRequired', $update.RebootRequired); + $PendingUpdateDetails.Add('IsPresent', $update.IsPresent); + $PendingUpdateDetails.Add('CveIDs', $update.CveIDs); + $PendingUpdateDetails.Add('BrowseOnly', $update.BrowseOnly); + $PendingUpdateDetails.Add('PerUser', $update.PerUser); + $PendingUpdateDetails.Add('AutoSelection', $update.AutoSelection); + $PendingUpdateDetails.Add('AutoDownload', $update.AutoDownload); + + [string]$name = [string]::Format('{0} [{1}]', $update.Title, $update.LastDeploymentChangeTime); + + if ($PendingUpdateNameCache.ContainsKey($name) -eq $FALSE) { + $PendingUpdateNameCache.Add($name, 1); + } else { + $PendingUpdateNameCache[$name] += 1; + $name = [string]::Format('{0} ({1})', $name, $PendingUpdateNameCache[$name]); + } + + $PendingUpdates.Add($name, $PendingUpdateDetails); + } + } catch { + if ($PendingUpdates.ContainsKey('Count') -eq $FALSE) { + $PendingUpdates.Add('count', 0); + } else { + $PendingUpdates['count'] = 0; + } + $PendingUpdates.Add('error', [string]::Format( + 'Failed to query Windows Update server: {0}', + $_.Exception.Message + )); + } + + return $PendingUpdates; +} \ No newline at end of file diff --git a/lib/provider/windows/Icinga_ProviderWindows.psm1 b/lib/provider/windows/Icinga_ProviderWindows.psm1 new file mode 100644 index 0000000..0d40c7d --- /dev/null +++ b/lib/provider/windows/Icinga_ProviderWindows.psm1 @@ -0,0 +1,11 @@ +function Show-IcingaWindowsData() +{ + $WindowsInformations = Get-CimInstance Win32_OperatingSystem; + + $windows_datails = @{}; + foreach($cpu_core in $WindowsInformations.CimInstanceProperties) { + $windows_datails.Add($cpu_core.Name, $cpu_core.Value); + } + + return $windows_datails; +} \ No newline at end of file