From 80ff188c903a5d147296612a75145f2f807b5f77 Mon Sep 17 00:00:00 2001 From: Crited Date: Fri, 12 Jul 2019 13:59:02 +0200 Subject: [PATCH 01/10] Added bios.psm1 (Library) and a provider/enums.psm1 --- icinga-module-windows.psm1 | 2 + lib/provider/bios.psm1 | 91 ++++++++++++++++++++++++++++++++++++++ lib/provider/enums.psm1 | 72 ++++++++++++++++++++++++++++++ 3 files changed, 165 insertions(+) create mode 100644 lib/provider/bios.psm1 create mode 100644 lib/provider/enums.psm1 diff --git a/icinga-module-windows.psm1 b/icinga-module-windows.psm1 index 3d84e5e..70c3552 100644 --- a/icinga-module-windows.psm1 +++ b/icinga-module-windows.psm1 @@ -9,6 +9,8 @@ #> +$global:IncludeDir = "$PSScriptRoot\lib"; + function Install-Icinga() { [string]$command = Get-Icinga-Command('setup'); diff --git a/lib/provider/bios.psm1 b/lib/provider/bios.psm1 new file mode 100644 index 0000000..ba9655f --- /dev/null +++ b/lib/provider/bios.psm1 @@ -0,0 +1,91 @@ +Import-Module $IncludeDir\provider\enums; + +function Show-IcingaBiosData() +{ + # Lets load some bios informations + $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; +} + +function Get-IcingaBiosSerialNumber() +{ + $bios = Get-CimInstance Win32_BIOS; + return @{'value' = $bios.SerialNumber; 'name' = 'SerialNumber'}; +} + +function Get-IcingaBiosVersion() +{ + $bios = Get-CimInstance Win32_BIOS; + return @{'value' = $bios.Version; 'name' = 'Version'}; +} + +function Get-IcingaBiosManufacturer() +{ + $bios = Get-CimInstance Win32_BIOS; + return @{'value' = $bios.Manufacturer; 'name' = 'Manufacturer'}; +} + +# Primary Bios seems to be relevant in dual-bios context +function Get-IcingaBiosPrimaryBios() +{ + $bios = Get-CimInstance Win32_BIOS; + return @{'value' = $bios.PrimaryBIOS; 'name' = 'PrimaryBIOS'}; +} + +function Get-IcingaBiosName() +{ + $bios = Get-CimInstance Win32_BIOS; + return @{'value' = $bios.Name; 'name' = 'Name'}; +} + +function Get-IcingaBiosStatus() +{ + $bios = Get-CimInstance Win32_BIOS; + return @{'value' = $bios.Status; 'name' = 'Status'}; +} + +function Get-IcingaBiosCaption() +{ + $bios = Get-CimInstance Win32_BIOS; + return @{'value' = $bios.Caption; 'name' = 'Caption'}; +} + +function Get-IcingaBiosSMBIOSBIOSVersion() +{ + $bios = Get-CimInstance Win32_BIOS; + return @{'value' = $bios.SMBIOSBIOSVersion; 'name' = 'SMBIOSBIOSVersion'}; +} + +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([int]$id, $ProviderEnums.BiosCharacteristics.([int]$id)); + } + + $output = $BIOSCharacteristics; + + if ($sorted) { + $output = $BIOSCharacteristics.GetEnumerator() | Sort-Object name; + } + + return @{'value' = $output; 'name' = 'BiosCharacteristics'}; +} diff --git a/lib/provider/enums.psm1 b/lib/provider/enums.psm1 new file mode 100644 index 0000000..a5425fd --- /dev/null +++ b/lib/provider/enums.psm1 @@ -0,0 +1,72 @@ +[hashtable]$BiosCharacteristics = @{ + 0 = 'Reserved'; + 1 = 'Reserved'; + 2 = 'Unknown'; + 3 = 'BIOS Characteristics Not Supported'; + 4 = 'ISA is supported'; + 5 = 'MCA is supported'; + 6 = 'EISA is supported'; + 7 = 'PCI is supported'; + 8 = 'PC Card (PCMCIA) is supported'; + 9 = 'Plug and Play is supported'; + 10 = 'APM is supported'; + 11 = 'BIOS is Upgradeable (Flash)'; + 12 = 'BIOS shadowing is allowed'; + 13 = 'VL-VESA is supported'; + 14 = 'ESCD support is available'; + 15 = 'Boot from CD is supported'; + 16 = 'Selectable Boot is supported'; + 17 = 'BIOS ROM is socketed'; + 18 = 'Boot From PC Card (PCMCIA) is supported'; + 19 = 'EDD (Enhanced Disk Drive) Specification is supported'; + 20 = 'Int 13h - Japanese Floppy for NEC 9800 1.2mb (3.5, 1k Bytes/Sector, 360 RPM) is supported'; + 21 = 'Int 13h - Japanese Floppy for Toshiba 1.2mb (3.5, 360 RPM) is supported'; + 22 = 'Int 13h - 5.25 / 360 KB Floppy Services are supported'; + 23 = 'Int 13h - 5.25 /1.2MB Floppy Services are supported'; + 24 = 'Int 13h - 3.5 / 720 KB Floppy Services are supported'; + 25 = 'Int 13h - 3.5 / 2.88 MB Floppy Services are supported'; + 26 = 'Int 5h, Print Screen Service is supported'; + 27 = 'Int 9h, 8042 Keyboard services are supported'; + 28 = 'Int 14h, Serial Services are supported'; + 29 = 'Int 17h, printer services are supported'; + 30 = 'Int 10h, CGA/Mono Video Services are supported'; + 31 = 'NEC PC-98'; + 32 = 'ACPI is supported'; + 33 = 'USB Legacy is supported'; + 34 = 'AGP is supported'; + 35 = 'I2O boot is supported'; + 36 = 'LS-120 boot is supported'; + 37 = 'ATAPI ZIP Drive boot is supported'; + 38 = '1394 boot is supported'; + 39 = 'Smart Battery is supported'; + 40 = 'Reserved for BIOS vendor'; + 41 = 'Reserved for BIOS vendor'; + 42 = 'Reserved for BIOS vendor'; + 43 = 'Reserved for BIOS vendor'; + 44 = 'Reserved for BIOS vendor'; + 45 = 'Reserved for BIOS vendor'; + 46 = 'Reserved for BIOS vendor'; + 47 = 'Reserved for BIOS vendor'; + 48 = 'Reserved for system vendor'; + 49 = 'Reserved for system vendor'; + 50 = 'Reserved for system vendor'; + 51 = 'Reserved for system vendor'; + 52 = 'Reserved for system vendor'; + 53 = 'Reserved for system vendor'; + 54 = 'Reserved for system vendor'; + 55 = 'Reserved for system vendor'; + 56 = 'Reserved for system vendor'; + 57 = 'Reserved for system vendor'; + 58 = 'Reserved for system vendor'; + 59 = 'Reserved for system vendor'; + 60 = 'Reserved for system vendor'; + 61 = 'Reserved for system vendor'; + 62 = 'Reserved for system vendor'; + 63 = 'Reserved for system vendor' +} + +[hashtable]$ProviderEnums = @{ + BiosCharacteristics = $BiosCharacteristics +} + +Export-ModuleMember -Variable @('ProviderEnums'); \ No newline at end of file From df8ef6665e7720716466c9ace5cbc004c8baf21a Mon Sep 17 00:00:00 2001 From: Crited Date: Tue, 16 Jul 2019 14:47:21 +0200 Subject: [PATCH 02/10] Added disk-module; extended enums to fit disk-modules --- lib/provider/disks.psm1 | 220 ++++++++++++++++++++++++++++++++++++++++ lib/provider/enums.psm1 | 19 +++- 2 files changed, 238 insertions(+), 1 deletion(-) create mode 100644 lib/provider/disks.psm1 diff --git a/lib/provider/disks.psm1 b/lib/provider/disks.psm1 new file mode 100644 index 0000000..8035065 --- /dev/null +++ b/lib/provider/disks.psm1 @@ -0,0 +1,220 @@ +function Show-IcingaDiskFullData { + + $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; +} + +function Get-IcingaDiskInformation() +{ + param( + # The value to fetch from Win32_DiskDrive + [string]$Parameter + ); + $DiskInformation = Get-CimInstance Win32_DiskDrive; + [hashtable]$DiskData = @{}; + + foreach ($id in $DiskInformation.DeviceID) { + $id = $id.trimstart(".\PHYSICALDRVE"); + $DiskData.Add($id.trim(), $DiskInformation.$Parameter); + } + + return $DiskData; +} +function Get-IcingaDiskPartitions() +{ + $LogicalDiskInfo = Get-WmiObject Win32_LogicalDiskToPartition; + [hashtable]$PartitionDiskByDriveLetter = @{}; + + foreach ($item in $LogicalDiskInfo) { + [string]$driveLetter = $item.Dependent.SubString( + $item.Dependent.LastIndexOf('=') + 1, + $item.Dependent.Length - $item.Dependent.LastIndexOf('=') - 1 + ); + $driveLetter = $driveLetter.Replace('"', '').trim(':'); + + [string]$diskPartition = $item.Antecedent.SubString( + $item.Antecedent.LastIndexOf('=') + 1, + $item.Antecedent.Length - $item.Antecedent.LastIndexOf('=') - 1 + ) + $diskPartition = $diskPartition.Replace('"', ''); + $diskDisk,$diskPartition = $diskPartition.split(','); + + $diskPartition = $diskPartition.trim("Partition #"); + $diskDisk = $diskDisk.trim("Disk #"); + $diskPartitionSize = Get-Partition -DriveLetter $driveLetter; + $PartitionDiskByDriveLetter.Add( + $driveLetter, + @{ + 'Disk' = $diskDisk; + 'Partition' = $diskPartition; + 'Size' = $diskPartitionSize.Size; + } + ); + } + 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-IcingaDiskFullData" + 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; + [hashtable]$DiskCapabilities = @{}; + + foreach ($id in $DiskInformation.Capabilities) { + $DiskCapabilities.Add([int]$id, $ProviderEnums.Capabilities.([int]$id)); + } + return @{'value' = $DiskCapabilities; 'name' = 'Capabilities'}; + +} +function Get-IcingaDiskSize +{ + $DiskSize = Get-IcingaDiskInformation -Parameter Size; + + return @{'value' = $DiskSize; 'name' = 'Size'}; +} + +function Get-IcingaDiskCaption +{ + $DiskCaption = Get-IcingaDiskInformation -Parameter Caption; + + return @{'value' = $DiskCaption; 'name' = 'Caption'}; +} + +function Get-IcingaDiskModel +{ + $DiskModel = Get-IcingaDiskInformation -Parameter Model; + return @{'value' = $DiskModel; 'name' = 'Model'}; +} + +function Get-IcingaDisk { + + $DiskInformation = Get-CimInstance Win32_DiskDrive; + $diskPartitionInformation = Get-IcingaDiskPartitions; + [hashtable]$DiskData = @{}; + + foreach ($id in $DiskInformation.DeviceID) { + [int]$id = $id.trimstart(".\PHYSICALDRVE"); + + $DiskData.Add( + $id, @{ + 'metadata' = @{ + 'Size' = $DiskInformation.Size; + 'Model' = $DiskInformation.Model; + 'Name' = $DiskInformation.Name.trim('.\'); + 'Manufacturer' = $DiskInformation.Manufacturer; + 'Cylinder' = $DiskInformation.TotalCylinders; + 'Sectors' = $DiskInformation.TotalSectors + }; + 'partitions' = $diskPartitionInformation + } + ); + } + + return $DiskData; +} \ No newline at end of file diff --git a/lib/provider/enums.psm1 b/lib/provider/enums.psm1 index a5425fd..b175397 100644 --- a/lib/provider/enums.psm1 +++ b/lib/provider/enums.psm1 @@ -65,8 +65,25 @@ 63 = 'Reserved for system vendor' } +[hashtable]$Capabilities = @{ + 0 = 'Unknown'; + 1 = 'Other'; + 2 = 'Sequential Access'; + 3 = 'Random Access'; + 4 = 'Supports Writing'; + 5 = 'Encryption'; + 6 = 'Compression'; + 7 = 'Supports Removeable Media'; + 8 = 'Manual Cleaning'; + 9 = 'Automatic Cleaning'; + 10 = 'SMART Notification'; + 11 = 'Supports Dual Sided Media'; + 12 = 'Predismount Eject Not Required' +} + [hashtable]$ProviderEnums = @{ - BiosCharacteristics = $BiosCharacteristics + BiosCharacteristics = $BiosCharacteristics; + Capabilities = $Capabilities; } Export-ModuleMember -Variable @('ProviderEnums'); \ No newline at end of file From dfd7d249eb37c9173c6595eb43630173c6a40172 Mon Sep 17 00:00:00 2001 From: Crited Date: Wed, 17 Jul 2019 07:52:09 +0200 Subject: [PATCH 03/10] Minor disks edit; basic cpu setup --- lib/provider/cpu.psm1 | 15 +++++++++++++++ lib/provider/disks.psm1 | 20 +++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 lib/provider/cpu.psm1 diff --git a/lib/provider/cpu.psm1 b/lib/provider/cpu.psm1 new file mode 100644 index 0000000..0988bdb --- /dev/null +++ b/lib/provider/cpu.psm1 @@ -0,0 +1,15 @@ +function Show-IcingaCPUData(){ + +$CPUInformations = Get-CimInstance Win32_Processor; +[hashtable]$PhysicalCPUData = @{}; + +foreach ($cpu_properties in $CPUInformations) { + $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.psm1 index 8035065..d17c051 100644 --- a/lib/provider/disks.psm1 +++ b/lib/provider/disks.psm1 @@ -192,7 +192,25 @@ function Get-IcingaDiskModel return @{'value' = $DiskModel; 'name' = 'Model'}; } -function Get-IcingaDisk { +function Get-IcingaDiskManufacturer +{ + $DiskManufacturer = Get-IcingaDiskInformation -Parameter Manufacturer; + return @{'value' = $DiskManufacturer; 'name' = 'Manufacturer'}; +} + +function Get-IcingaDiskTotalCylinders +{ + $DiskTotalCylinders = Get-IcingaDiskInformation -Parameter TotalCylinders; + return @{'value' = $DiskTotalCylinders; 'name' = 'TotalCylinders'}; +} + +function Get-IcingaDiskTotalSectors +{ + $DiskTotalSectors = Get-IcingaDiskInformation -Parameter TotalSectors; + return @{'value' = $DiskTotalSectors; 'name' = 'TotalSectors'}; +} + +function Get-IcingaDisks { $DiskInformation = Get-CimInstance Win32_DiskDrive; $diskPartitionInformation = Get-IcingaDiskPartitions; From 504c18ef005e70f0f7111c036482d394c65b5884 Mon Sep 17 00:00:00 2001 From: Crited Date: Wed, 17 Jul 2019 11:28:22 +0200 Subject: [PATCH 04/10] cpu first draft --- lib/provider/cpu.psm1 | 124 +++++++++++++++++++++++- lib/provider/disks.psm1 | 2 +- lib/provider/enums.psm1 | 206 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 326 insertions(+), 6 deletions(-) diff --git a/lib/provider/cpu.psm1 b/lib/provider/cpu.psm1 index 0988bdb..b34767d 100644 --- a/lib/provider/cpu.psm1 +++ b/lib/provider/cpu.psm1 @@ -1,9 +1,10 @@ -function Show-IcingaCPUData(){ +function Show-IcingaCPUData() +{ -$CPUInformations = Get-CimInstance Win32_Processor; +$CPUInformation = Get-CimInstance Win32_Processor; [hashtable]$PhysicalCPUData = @{}; -foreach ($cpu_properties in $CPUInformations) { +foreach ($cpu_properties in $CPUInformation) { $cpu_datails = @{}; foreach($cpu_core in $cpu_properties.CimInstanceProperties) { $cpu_datails.Add($cpu_core.Name, $cpu_core.Value); @@ -12,4 +13,121 @@ foreach ($cpu_properties in $CPUInformations) { } return $PhysicalCPUData; +} + +function Get-IcingaCPUs() +{ + $CPUInformation = Get-CimInstance Win32_Processor; + [hashtable]$CPUData = @{}; + + foreach ($id in $CPUInformation.DeviceID) { + $CPUData.Add( + $id, @{ + 'metadata' = @{ + 'Name' = $CPUInformation.Name; + 'DeviceID' = $CPUInformation.DeviceID; + 'ProcessorID' = $CPUInformation.ProcessorId; + 'UniqueID' = $CPUInformation.UniqueId; + 'Description' = $CPUInformation.Description; + 'OtherFamilyDescription' = $CPUInformation.OtherFamilyDescription; + 'Caption' = $CPUInformation.Caption; + 'Version' = $CPUInformation.Version; + 'SerialNumber' = $CPUInformation.SerialNumber; + 'Manufacturer' = $CPUInformation.Manufacturer; + 'Number of Cores' = $CPUInformation.NumberOfCores; + 'Family' = $CPUFamily.Family; + 'Architecture' = $CPUArchitecture.Architecture; + 'ProcessorType' = $CPUProcessorType.ProcessorType; + 'StatusInfo' = $CPUStatusInfo.StatusInfo; + 'Status' = $CPUInformation.Status; + 'CPUStatus' = $CPUInformation.CpuStatus; + 'NumberOfLogicalProcessors' = $CPUStatusInfo.NumberOfLogicalProcessors; + 'Level'= $CPUInformation.Level; + 'Availability' = $CPUAvailability.Availability; + + }; + 'errors' = @{ + 'LastErrorCode' = $CPUInformation.LastErrorCode; + 'ErrorCleared' = $CPUInformation.ErrorCleared; + 'ErrorDescription' = $CPUInformation.ErrorDescription; + 'ConfigManagerErrorCode' = $CPUConfigManagerErrorCode.ConfigManagerErrorCode; + }; + 'perfdata' = @{ + 'LoadPercentage' = $CPUInformation.LoadPercentage; + 'CurrentVoltage' = $CPUInformation.CurrentVoltage; + 'ThreadCount' = $CPUInformation.ThreadCount; + } + } + ); + } + return $CPUData; +} + + +function Get-IcingaCPUArchitecture() +{ + + $CPUInformation = Get-CimInstance Win32_Processor; + [hashtable]$CPUArchitecture = @{}; + + foreach ($id in $CPUInformation.Architecture) { + $CPUArchitecture.Add([int]$id, $ProviderEnums.CPUArchitecture.([int]$id)); + } + return @{'value' = $CPUArchitecture; 'name' = 'Architecture'}; +} + +function Get-IcingaCPUProcessorType() +{ + $CPUInformation = Get-CimInstance Win32_Processor; + [hashtable]$CPUProcessorType = @{}; + + foreach ($id in $CPUInformation.ProcessorType) { + $CPUProcessorType.Add([int]$id, $ProviderEnums.CPUProcessorType.([int]$id)); + } + return @{'value' = $CPUProcessorType; 'name' = 'ProcessorType'}; +} + +function Get-IcingaCPUStatusInfo() +{ + $CPUInformation = Get-CimInstance Win32_Processor; + [hashtable]$CPUStatusInfo = @{}; + + foreach ($id in $CPUInformation.StatusInfo) { + $CPUStatusInfo.Add([int]$id, $ProviderEnums.CPUStatusInfo.([int]$id)); + } + return @{'value' = $CPUStatusInfo; 'name' = 'StatusInfo'}; +} + +function Get-IcingaCPUFamily() +{ + $CPUInformation = Get-CimInstance Win32_Processor; + [hashtable]$CPUFamily = @{}; + + foreach ($id in $CPUInformation.Family) { + $CPUFamily.Add([int]$id, $ProviderEnums.CPUFamily.([int]$id)); + } + return @{'value' = $CPUFamily; 'name' = 'Family'}; +} + +function Get-IcingaCPUConfigManagerErrorCode() +{ + $CPUInformation = Get-CimInstance Win32_Processor; + [hashtable]$CPUConfigManagerErrorCode = @{}; + + foreach ($id in $CPUInformation.ConfigManagerErrorCode) { + $CPUConfigManagerErrorCode.Add([int]$id, $ProviderEnums.CPUConfigManagerErrorCode.([int]$id)); + } + return @{'value' = $CPUConfigManagerErrorCode; 'name' = 'ConfigManagerErrorCode'}; +} + +function Get-IcingaCPUAvailability() +{ + $CPUInformation = Get-CimInstance Win32_Processor; + [hashtable]$CPUAvailability = @{}; + + foreach ($id in $CPUInformation.Availability) { + $CPUAvailability.Add([int]$id, $ProviderEnums.CPUAvailability.([int]$id)); + } + + return @{'value' = $CPUAvailability; 'name' = 'Availability'}; } \ No newline at end of file diff --git a/lib/provider/disks.psm1 b/lib/provider/disks.psm1 index d17c051..f8af26c 100644 --- a/lib/provider/disks.psm1 +++ b/lib/provider/disks.psm1 @@ -167,7 +167,7 @@ function Get-IcingaDiskCapabilities [hashtable]$DiskCapabilities = @{}; foreach ($id in $DiskInformation.Capabilities) { - $DiskCapabilities.Add([int]$id, $ProviderEnums.Capabilities.([int]$id)); + $DiskCapabilities.Add([int]$id, $ProviderEnums.DiskCapabilities.([int]$id)); } return @{'value' = $DiskCapabilities; 'name' = 'Capabilities'}; diff --git a/lib/provider/enums.psm1 b/lib/provider/enums.psm1 index b175397..938e236 100644 --- a/lib/provider/enums.psm1 +++ b/lib/provider/enums.psm1 @@ -65,7 +65,7 @@ 63 = 'Reserved for system vendor' } -[hashtable]$Capabilities = @{ +[hashtable]$DiskCapabilities = @{ 0 = 'Unknown'; 1 = 'Other'; 2 = 'Sequential Access'; @@ -81,9 +81,211 @@ 12 = 'Predismount Eject Not Required' } +[hashtable]$CPUArchitecture = @{ + 0='x86'; + 1='MIPS'; + 2='Alpha'; + 3='PowerPC'; + 6='ia64'; + 9='x64'; +} + +[hashtable]$CPUProcessorType = @{ + 1='Other'; + 2='Unknown'; + 3='Central Processor'; + 4='Math Processor'; + 5='DSP Processor'; + 6='Video Processor'; +} + +[hashtable]$CPUStatusInfo = @{ + 1='Other' + 2='Unknown' + 3='Enabled' + 4='Disabled' + 5='Not Applicable' +} + +[hashtable]$CPUFamily = @{ + 1='Other' + 2='Unknown' + 3='8086' + 4='80286' + 5='80386' + 6='80486' + 7='8087' + 8='80287' + 9='80387' + 10='80487' + 11='Pentium(R) brand' + 12='Pentium(R) Pro' + 13='Pentium(R) II' + 14='Pentium(R) processor with MMX(TM) technology' + 15='Celeron(TM)' + 16='Pentium(R) II Xeon(TM)' + 17='Pentium(R) III' + 18='M1 Family' + 19='M2 Family' + 24='K5 Family' + 25='K6 Family' + 26='K6-2' + 27='K6-3' + 28='AMD Athlon(TM) Processor Family' + 29='AMD(R) Duron(TM) Processor' + 30='AMD29000 Family' + 31='K6-2+' + 32='Power PC Family' + 33='Power PC 601' + 34='Power PC 603' + 35='Power PC 603+' + 36='Power PC 604' + 37='Power PC 620' + 38='Power PC X704' + 39='Power PC 750' + 48='Alpha Family' + 49='Alpha 21064' + 50='Alpha 21066' + 51='Alpha 21164' + 52='Alpha 21164PC' + 53='Alpha 21164a' + 54='Alpha 21264' + 55='Alpha 21364' + 64='MIPS Family' + 65='MIPS R4000' + 66='MIPS R4200' + 67='MIPS R4400' + 68='MIPS R4600' + 69='MIPS R10000' + 80='SPARC Family' + 81='SuperSPARC' + 82='microSPARC II' + 83='microSPARC IIep' + 84='UltraSPARC' + 85='UltraSPARC II' + 86='UltraSPARC IIi' + 87='UltraSPARC III' + 88='UltraSPARC IIIi' + 96='68040' + 97='68xxx Family' + 98='68000' + 99='68010' + 100='68020' + 101='68030' + 112='Hobbit Family' + 120='Crusoe(TM) TM5000 Family' + 121='Crusoe(TM) TM3000 Family' + 122='Efficeon(TM) TM8000 Family' + 128='Weitek' + 130='Itanium(TM) Processor' + 131='AMD Athlon(TM) 64 Processor Family' + 132='AMD Opteron(TM) Family' + 144='PA-RISC Family' + 145='PA-RISC 8500' + 146='PA-RISC 8000' + 147='PA-RISC 7300LC' + 148='PA-RISC 7200' + 149='PA-RISC 7100LC' + 150='PA-RISC 7100' + 160='V30 Family' + 176='Pentium(R) III Xeon(TM)' + 177='Pentium(R) III Processor with Intel(R) SpeedStep(TM) Technology' + 178='Pentium(R) 4' + 179='Intel(R) Xeon(TM)' + 180='AS400 Family' + 181='Intel(R) Xeon(TM) processor MP' + 182='AMD AthlonXP(TM) Family' + 183='AMD AthlonMP(TM) Family' + 184='Intel(R) Itanium(R) 2' + 185='Intel Pentium M Processor' + 190='K7' + 200='IBM390 Family' + 201='G4' + 202='G5' + 203='G6' + 204='z/Architecture base' + 250='i860' + 251='i960' + 260='SH-3' + 261='SH-4' + 280='ARM' + 281='StrongARM' + 300='6x86' + 301='MediaGX' + 302='MII' + 320='WinChip' + 350='DSP' + 500='Video Processor' +} + +[hashtable]$CPUConfigManagerErrorCode = @{ + 0='This device is working properly.'; + 1='This device is not configured correctly.'; + 2='Windows cannot load the driver for this device.'; + 3='The driver for this device might be corrupted, or your system may be running low on memory or other resources.'; + 4='This device is not working properly. One of its drivers or your registry might be corrupted.'; + 5='The driver for this device needs a resource that Windows cannot manage.'; + 6='The boot configuration for this device conflicts with other devices.'; + 7='Cannot filter.'; + 8='The driver loader for the device is missing.'; + 9='This device is not working properly because the controlling firmware is reporting the resources for the device incorrectly.'; + 10='This device cannot start.'; + 11=' This device failed.'; + 12='This device cannot find enough free resources that it can use.'; + 13="Windows cannot verify this device’s resources."; + 14='This device cannot work properly until you restart your computer.'; + 15='This device is not working properly because there is probably a re-enumeration problem.'; + 16='Windows cannot identify all the resources this device uses.'; + 17='This device is asking for an unknown resource type.'; + 18='Reinstall the drivers for this device.'; + 19='Your registry might be corrupted.'; + 20='Failure using the VxD loader.'; + 21='System failure: Try changing the driver for this device. If that does not work, see your hardware documentation. Windows is removing this device.'; + 22='This device is disabled.'; + 23="System failure: Try changing the driver for this device. If that doesn’t work, see your hardware documentation."; + 24="This device is not present, is not working properly, or does not have all its drivers installed."; + 25="Windows is still setting up this device."; + 26="Windows is still setting up this device."; + 27="This device does not have valid log configuration."; + 28="The drivers for this device are not installed."; + 29="This device is disabled because the firmware of the device did not give it the required resources."; + 30="This device is using an Interrupt Request (IRQ) resource that another device is using."; + 31='This device is not working properly because Windows cannot load the drivers required for this device.'; +} + +[hashtable]$CPUAvailability = @{ + 1='Other'; + 2='Unknown'; + 3='Running/Full Power'; + 4='Warning'; + 5='In Test'; + 6='Not Applicable'; + 7='Power Off'; + 8='Off Line'; + 9='Off Duty'; + 10='Degraded'; + 11='Not Installed'; + 12='Install Error'; + 13='Power Save - Unknown'; + 14='Power Save - Low Power Mode'; + 15='Power Save - Standby'; + 16='Power Cycle'; + 17='Power Save - Warning'; + 18='Paused'; + 19='Not Ready'; + 20='Not Configured'; + 21='Quiesced'; +} + [hashtable]$ProviderEnums = @{ BiosCharacteristics = $BiosCharacteristics; - Capabilities = $Capabilities; + DiskCapabilities = $DiskCapabilities; + CPUArchitecture = $CPUArchitecture; + CPUProcessorType = $CPUProcessorType; + CPUStatusInfo = $CPUStatusInfo; + CPUFamily = $CPUFamily; + CPUConfigManagerErrorCode = $CPUConfigManagerErrorCode; + CPUAvailability = $CPUAvailability; } Export-ModuleMember -Variable @('ProviderEnums'); \ No newline at end of file From 8bce5c6a4c5f0a7053c25932f2871a2be1be5213 Mon Sep 17 00:00:00 2001 From: Crited Date: Thu, 18 Jul 2019 14:20:23 +0200 Subject: [PATCH 05/10] Major fixes regarding all lib/providers, expanded upon memory.psm1, added some comments for future reference --- lib/provider/bios.psm1 | 42 ++++- lib/provider/cpu.psm1 | 251 ++++++++++++++++++++++------ lib/provider/disks.psm1 | 28 +++- lib/provider/enums.psm1 | 343 +++++++++++++++++++++++++-------------- lib/provider/memory.psm1 | 196 ++++++++++++++++++++++ 5 files changed, 685 insertions(+), 175 deletions(-) create mode 100644 lib/provider/memory.psm1 diff --git a/lib/provider/bios.psm1 b/lib/provider/bios.psm1 index ba9655f..e2acd7f 100644 --- a/lib/provider/bios.psm1 +++ b/lib/provider/bios.psm1 @@ -1,8 +1,10 @@ Import-Module $IncludeDir\provider\enums; +<################################################################################################## +################# Runspace "Show-Icinga{BIOS}" #################################################### +##################################################################################################> function Show-IcingaBiosData() { - # Lets load some bios informations $BIOSInformation = Get-CimInstance Win32_BIOS; [hashtable]$BIOSData = @{}; @@ -15,6 +17,40 @@ function Show-IcingaBiosData() return $BIOSData; } +<################################################################################################## +################# Runspace "Get-Icinga{BIOS}" ##################################################### +##################################################################################################> +function Get-IcingaBios() +{ + <# Collects the most important BIOS informations, + e.g. name, version, manufacturer#> + $BIOSInformation = Get-CimInstance Win32_BIOS; + [hashtable]$BIOSCharacteristics = @{}; + [hashtable]$BIOSData = @{}; + + foreach ($id in $BIOSInformation.BiosCharacteristics) { + $BIOSCharacteristics.Add([string]$id, $ProviderEnums.BiosCharacteristics.Item([int]$id)); + } + + $BIOSData.Add( + 'bios', @{ + 'metadata' = @{ + 'Name' = $BIOSInformation.Name; + 'Caption' = $BIOSInformation.Caption; + 'Manufacturer' = $BIOSInformation.Manufacturer; + 'PrimaryBIOS' = $BIOSInformation.PrimaryBIOS; + 'SerialNumber' = $BIOSInformation.SerialNumber; + 'SMBIOSBIOSVersion' = $BIOSInformation.SMBIOSBIOSVersion; + 'SoftwareElementID' = $BIOSInformation.SoftwareElementID; + 'Status' = $BIOSInformation.Status; + 'Version' = $BIOSInformation.Version; + 'BiosCharacteristics' = $BIOSCharacteristics; + } + } + ); + return $BIOSData; + } + function Get-IcingaBiosSerialNumber() { $bios = Get-CimInstance Win32_BIOS; @@ -33,7 +69,7 @@ function Get-IcingaBiosManufacturer() return @{'value' = $bios.Manufacturer; 'name' = 'Manufacturer'}; } -# Primary Bios seems to be relevant in dual-bios context +# Primary Bios might be more relevant in dual bios context function Get-IcingaBiosPrimaryBios() { $bios = Get-CimInstance Win32_BIOS; @@ -78,7 +114,7 @@ function Get-IcingaBiosCharacteristics() [hashtable]$BIOSCharacteristics = @{}; foreach ($id in $bios.BiosCharacteristics) { - $BIOSCharacteristics.Add([int]$id, $ProviderEnums.BiosCharacteristics.([int]$id)); + $BIOSCharacteristics.Add([string]$id, $ProviderEnums.BiosCharacteristics.Item([int]$id)); } $output = $BIOSCharacteristics; diff --git a/lib/provider/cpu.psm1 b/lib/provider/cpu.psm1 index b34767d..bdef95a 100644 --- a/lib/provider/cpu.psm1 +++ b/lib/provider/cpu.psm1 @@ -1,3 +1,8 @@ +Import-Module $IncludeDir\provider\enums; + +<################################################################################################## +################# Runspace "Show-Icinga{CPU}" ##################################################### +##################################################################################################> function Show-IcingaCPUData() { @@ -15,12 +20,19 @@ foreach ($cpu_properties in $CPUInformation) { return $PhysicalCPUData; } +<################################################################################################## +################# Runspace "Get-Icinga{Memory}" ################################################### +##################################################################################################> function Get-IcingaCPUs() { + <# Collects the most important CPU informations, + e.g. name, version, manufacturer#> $CPUInformation = Get-CimInstance Win32_Processor; [hashtable]$CPUData = @{}; foreach ($id in $CPUInformation.DeviceID) { + $id=$id.trim('CPU'); + $CPUData.Add( $id, @{ 'metadata' = @{ @@ -34,100 +46,241 @@ function Get-IcingaCPUs() 'Version' = $CPUInformation.Version; 'SerialNumber' = $CPUInformation.SerialNumber; 'Manufacturer' = $CPUInformation.Manufacturer; - 'Number of Cores' = $CPUInformation.NumberOfCores; - 'Family' = $CPUFamily.Family; - 'Architecture' = $CPUArchitecture.Architecture; - 'ProcessorType' = $CPUProcessorType.ProcessorType; - 'StatusInfo' = $CPUStatusInfo.StatusInfo; + 'NumberOfCores' = $CPUInformation.NumberOfCores; + 'PartNumber' = $CPUInformation.PartNumber; 'Status' = $CPUInformation.Status; 'CPUStatus' = $CPUInformation.CpuStatus; - 'NumberOfLogicalProcessors' = $CPUStatusInfo.NumberOfLogicalProcessors; + 'Revision' = $CPUInformation.Revision; + 'NumberOfLogicalProcessors' = $CPUInformation.NumberOfLogicalProcessors; 'Level'= $CPUInformation.Level; - 'Availability' = $CPUAvailability.Availability; - + 'AddressWidth' = $CPUInformation.AddressWidth; + 'Stepping' = $CPUInformation.Stepping; + 'SocketDesignation' = $CPUInformation.SocketDesignation; + 'Family' = @{ + 'raw' = $CPUInformation.Family; + 'value' = $ProviderEnums.CPUFamily[[int]$CPUInformation.Family]; + }; + 'Architecture' = @{ + 'raw' = $CPUInformation.Architecture; + 'value' = $ProviderEnums.CPUArchitecture[[int]$CPUInformation.Architecture]; + }; + 'ProcessorType' = @{ + 'raw' = $CPUInformation.ProcessorType; + 'value' = $ProviderEnums.CPUProcessorType[[int]$CPUInformation.ProcessorType]; + }; + 'StatusInfo' = @{ + 'raw' = $CPUInformation.StatusInfo; + 'value' = $ProviderEnums.CPUStatusInfo[[int]$CPUInformation.StatusInfo]; + }; + 'Availability' = @{ + 'raw' = $CPUInformation.Availability; + 'value' = $ProviderEnums.CPUAvailability[[int]$CPUInformation.Availability]; + }; + 'PowerManagementCapabilities' = @{ + 'raw' = $CPUInformation.PowerManagementCapabilities; + 'value' = $ProviderEnums.CPUPowerManagementCapabilities[[int]$CPUInformation.PowerManagementCapabilities]; + } }; 'errors' = @{ 'LastErrorCode' = $CPUInformation.LastErrorCode; 'ErrorCleared' = $CPUInformation.ErrorCleared; 'ErrorDescription' = $CPUInformation.ErrorDescription; - 'ConfigManagerErrorCode' = $CPUConfigManagerErrorCode.ConfigManagerErrorCode; + 'ConfigManagerErrorCode' = @{ + 'raw' = [int]$CPUInformation.ConfigManagerErrorCode; + 'value' = $ProviderEnums.CPUConfigManagerErrorCode.([int]$CPUInformation.ConfigManagerErrorCode); + } }; - 'perfdata' = @{ + 'specs' = @{ 'LoadPercentage' = $CPUInformation.LoadPercentage; 'CurrentVoltage' = $CPUInformation.CurrentVoltage; 'ThreadCount' = $CPUInformation.ThreadCount; + 'L3CacheSize' = $CPUInformation.L3CacheSize; + 'L2CacheSpeed' = $CPUInformation.L2CacheSpeed; + 'L2CacheSize' = $CPUInformation.L2CacheSize; + 'VoltageCaps' = $CPUInformation.VoltageCaps; + 'CurrentClockSpeed' = $CPUInformation.CurrentClockSpeed; } } - ); + ); } return $CPUData; } +function Get-IcingaCPUInformation() +{ + <# Fetches the information for other more specific Get-IcingaCPU-functions + e.g. Get-IcingaCPUThreadCount; Get-IcingaCPULoadPercentage. + Can be used to fetch information regarding a value of your choice. #> + param( + [string]$Parameter + ); + $CPUInformation = Get-CimInstance Win32_Processor; + [hashtable]$CPUData = @{}; + + foreach ($id in $CPUInformation.DeviceID) { + $CPUData.Add($id.trim('CPU'), $CPUInformation.$Parameter); + } + + return $CPUData; +} + +function Get-IcingaCPUInformationWithEnums() +{ <# Fetches the information of other more specific Get-IcingaCPU-functions, + which require a enums key-value pair to resolve their code + e.g Get-IcingaCPUFamily, e.g. Get-IcingaCPUArchitecture#> + param( + [string]$Parameter + ); + + $CPUInformation = Get-CimInstance Win32_Processor; + $Prefix = "CPU"; + + [hashtable]$CPUData = @{}; + + foreach ($id in $CPUInformation.DeviceID) { + $id=$id.trim('CPU'); + $CPUData.Add( + $id, @{ + 'raw' = $CPUInformation.$Parameter; + 'value' = $ProviderEnums."$Prefix$Parameter"[[int]$CPUInformation.$Parameter] + } + ); + } + return $CPUData; +} + +function Get-IcingaCPUErrors() +{ + $CPUInformation = Get-CimInstance Win32_Processor; + [hashtable]$CPUData = @{}; + + foreach ($id in $CPUInformation.DeviceID) { + $id=$id.trim('CPU'); + $CPUData.Add( + $id, @{ + 'errors' = @{ + 'LastErrorCode' = $CPUInformation.LastErrorCode; + 'ErrorCleared' = $CPUInformation.ErrorCleared; + 'ErrorDescription' = $CPUInformation.ErrorDescription; + 'ConfigManagerErrorCode' = @{ + 'raw' = [int]$CPUInformation.ConfigManagerErrorCode; + 'value' = $ProviderEnums.CPUConfigManagerErrorCode.([int]$CPUInformation.ConfigManagerErrorCode); + } + } + } + ); + } + return $CPUData; +} function Get-IcingaCPUArchitecture() { + $CPUArchitecture = Get-IcingaCPUInformationWithEnums -Parameter Architecture; - $CPUInformation = Get-CimInstance Win32_Processor; - [hashtable]$CPUArchitecture = @{}; - - foreach ($id in $CPUInformation.Architecture) { - $CPUArchitecture.Add([int]$id, $ProviderEnums.CPUArchitecture.([int]$id)); - } - return @{'value' = $CPUArchitecture; 'name' = 'Architecture'}; + return @{'value' = $CPUArchitecture; 'name' = 'Architecture'}; } function Get-IcingaCPUProcessorType() { - $CPUInformation = Get-CimInstance Win32_Processor; - [hashtable]$CPUProcessorType = @{}; + $CPUProcessorType = Get-IcingaCPUInformationWithEnums -Parameter ProcessorType; - foreach ($id in $CPUInformation.ProcessorType) { - $CPUProcessorType.Add([int]$id, $ProviderEnums.CPUProcessorType.([int]$id)); - } - return @{'value' = $CPUProcessorType; 'name' = 'ProcessorType'}; + return @{'value' = $CPUProcessorType; 'name' = 'ProcessorType'}; } function Get-IcingaCPUStatusInfo() { - $CPUInformation = Get-CimInstance Win32_Processor; - [hashtable]$CPUStatusInfo = @{}; + $CPUStatusInfo = Get-IcingaCPUInformationWithEnums -Parameter StatusInfo; - foreach ($id in $CPUInformation.StatusInfo) { - $CPUStatusInfo.Add([int]$id, $ProviderEnums.CPUStatusInfo.([int]$id)); - } - return @{'value' = $CPUStatusInfo; 'name' = 'StatusInfo'}; + return @{'value' = $CPUStatusInfo; 'name' = 'StatusInfo'}; } function Get-IcingaCPUFamily() { - $CPUInformation = Get-CimInstance Win32_Processor; - [hashtable]$CPUFamily = @{}; + $CPUFamily = Get-IcingaCPUInformationWithEnums -Parameter Family; - foreach ($id in $CPUInformation.Family) { - $CPUFamily.Add([int]$id, $ProviderEnums.CPUFamily.([int]$id)); - } - return @{'value' = $CPUFamily; 'name' = 'Family'}; + return @{'value' = $CPUFamily; 'name' = 'Family'}; } function Get-IcingaCPUConfigManagerErrorCode() { - $CPUInformation = Get-CimInstance Win32_Processor; - [hashtable]$CPUConfigManagerErrorCode = @{}; + $CPUConfigManagerErrorCode = Get-IcingaCPUInformationWithEnums -Parameter ConfigManagerErrorCode; - foreach ($id in $CPUInformation.ConfigManagerErrorCode) { - $CPUConfigManagerErrorCode.Add([int]$id, $ProviderEnums.CPUConfigManagerErrorCode.([int]$id)); - } - return @{'value' = $CPUConfigManagerErrorCode; 'name' = 'ConfigManagerErrorCode'}; + return @{'value' = $CPUConfigManagerErrorCode; 'name' = 'ConfigManagerErrorCode'}; } function Get-IcingaCPUAvailability() { - $CPUInformation = Get-CimInstance Win32_Processor; - [hashtable]$CPUAvailability = @{}; - - foreach ($id in $CPUInformation.Availability) { - $CPUAvailability.Add([int]$id, $ProviderEnums.CPUAvailability.([int]$id)); - } + $CPUAvailability = Get-IcingaCPUInformationWithEnums -Parameter Availability; - return @{'value' = $CPUAvailability; 'name' = 'Availability'}; + return @{'value' = $CPUAvailability; 'name' = 'Availability'}; +} + +function Get-IcingaCPUPowerManagementCapabilities() +{ + $CPUPowerManagementCapabilities = Get-IcingaCPUInformationWithEnums -Parameter PowerManagementCapabilities; + + return @{'value' = $CPUPowerManagementCapabilities; 'name' = 'PowerManagementCapabilities'}; +} + +function Get-IcingaCPULoadPercentage() +{ + $CPULoadPercentage = Get-IcingaCPUInformation -Parameter LoadPercentage; + + return @{'value' = $CPULoadPercentage; 'name' = 'LoadPercentage'}; +} + +function Get-IcingaCPUCurrentVoltage() +{ + $CPUCurrentVoltage = Get-IcingaCPUInformation -Parameter CurrentVoltage; + + return @{'value' = $CPUCurrentVoltage; 'name' = 'CurrentVoltage'}; +} + +function Get-IcingaCPUThreadCount() +{ + $CPUThreadCount = Get-IcingaCPUInformation -Parameter ThreadCount; + + return @{'value' = $CPUThreadCount; 'name' = 'ThreadCount'}; +} + +function Get-IcingaCPUL3CacheSize() +{ + $CPUL3CacheSize = Get-IcingaCPUInformation -Parameter L3CacheSize; + + return @{'value' = $CPUL3CacheSize; 'name' = 'L3CacheSize'}; +} + +function Get-IcingaCPUL2CacheSize() +{ + $CPUL2CacheSize = Get-IcingaCPUInformation -Parameter L2CacheSize; + + return @{'value' = $CPUL2CacheSize; 'name' = 'L2CacheSize'}; +} + +function Get-IcingaCPUL2CacheSpeed() +{ + $CPUL2CacheSpeed = Get-IcingaCPUInformation -Parameter L2CacheSpeed; + + return @{'value' = $CPUL2CacheSpeed; 'name' = 'L2CacheSpeed'}; +} + +function Get-IcingaCPUVoltageCaps() +{ + $CPUVoltageCaps = Get-IcingaCPUInformation -Parameter VoltageCaps; + + return @{'value' = $CPUVoltageCaps; 'name' = 'VoltageCaps'}; +} + +function Get-IcingaCPUCurrentClockSpeed() +{ + $CPUCurrentClockSpeed = Get-IcingaCPUInformation -Parameter CurrentClockSpeed; + + return @{'value' = $CPUCurrentClockSpeed; 'name' = 'CurrentClockSpeed'}; +} + +function Get-IcingaCPUNumberOfLogicalProcessors() +{ + $CPUNumberOfLogicalProcessors = Get-IcingaCPUInformation -Parameter NumberOfLogicalProcessors; + + return @{'value' = $CPUNumberOfLogicalProcessors; 'name' = 'NumberOfLogicalProcessors'}; } \ No newline at end of file diff --git a/lib/provider/disks.psm1 b/lib/provider/disks.psm1 index f8af26c..d689a33 100644 --- a/lib/provider/disks.psm1 +++ b/lib/provider/disks.psm1 @@ -1,4 +1,10 @@ -function Show-IcingaDiskFullData { +Import-Module $IncludeDir\provider\enums; + +<################################################################################################## +################# Runspace "Show-Icinga{Disk}" #################################################### +##################################################################################################> + +function Show-IcingaDiskData { $DisksInformations = Get-CimInstance Win32_DiskDrive; @@ -84,8 +90,15 @@ function Show-IcingaDiskPhysical() return $PhysicalDiskData; } +<################################################################################################## +################# Runspace "Get-Icinga{Disk}" #################################################### +##################################################################################################> + function Get-IcingaDiskInformation() { + <# Fetches the information for other more specific Get-IcingaDisk-functions + e.g. Get-IcingaDiskModel; Get-IcingaDiskManufacturer. + Can be used to fetch information regarding a value of your choice. #> param( # The value to fetch from Win32_DiskDrive [string]$Parameter @@ -93,7 +106,7 @@ function Get-IcingaDiskInformation() $DiskInformation = Get-CimInstance Win32_DiskDrive; [hashtable]$DiskData = @{}; - foreach ($id in $DiskInformation.DeviceID) { + foreach ($id in $DiskInformation.DeviceID) { $id = $id.trimstart(".\PHYSICALDRVE"); $DiskData.Add($id.trim(), $DiskInformation.$Parameter); } @@ -102,6 +115,9 @@ function Get-IcingaDiskInformation() } function Get-IcingaDiskPartitions() { + <# Fetches all the most important informations regarding partitions + e.g. physical disk; partition, size + , also collects partition information for Get-IcingaDisks #> $LogicalDiskInfo = Get-WmiObject Win32_LogicalDiskToPartition; [hashtable]$PartitionDiskByDriveLetter = @{}; @@ -141,7 +157,7 @@ function Get-IcingaDiskPartitionSize() [hashtable]$PartitionSizeByDriveLetter = @{}; - # Should be dependent on the driveLetters returned in: "Show-IcingaDiskFullData" + # Should be dependent on the driveLetters returned in: "Show-IcingaDiskData" for ($test = 0; $test -lt 26; $test++) { $DiskDriveLetter = ([char](65 + $test)) @@ -211,12 +227,14 @@ function Get-IcingaDiskTotalSectors } function Get-IcingaDisks { - + <# Collects all the most important Disk-Informations, + e.g. size, model, sectors, cylinders + Is dependent on Get-IcingaDiskPartitions#> $DiskInformation = Get-CimInstance Win32_DiskDrive; $diskPartitionInformation = Get-IcingaDiskPartitions; [hashtable]$DiskData = @{}; - foreach ($id in $DiskInformation.DeviceID) { + foreach ($id in $DiskInformation.DeviceID) { [int]$id = $id.trimstart(".\PHYSICALDRVE"); $DiskData.Add( diff --git a/lib/provider/enums.psm1 b/lib/provider/enums.psm1 index 938e236..6903ec0 100644 --- a/lib/provider/enums.psm1 +++ b/lib/provider/enums.psm1 @@ -1,8 +1,13 @@ -[hashtable]$BiosCharacteristics = @{ + +<################################################################################################## +################# /lib/provider/bios.psm1 ######################################################### +##################################################################################################> + +[hashtable]$BiosCharacteristics = @{ 0 = 'Reserved'; 1 = 'Reserved'; 2 = 'Unknown'; - 3 = 'BIOS Characteristics Not Supported'; + 3 = 'BIOS Characteristics Not Supported'; 4 = 'ISA is supported'; 5 = 'MCA is supported'; 6 = 'EISA is supported'; @@ -65,7 +70,11 @@ 63 = 'Reserved for system vendor' } -[hashtable]$DiskCapabilities = @{ +<################################################################################################## +################# /lib/provider/disks.psm1 ######################################################## +##################################################################################################> + +[hashtable]$DiskCapabilities = @{ 0 = 'Unknown'; 1 = 'Other'; 2 = 'Sequential Access'; @@ -78,9 +87,13 @@ 9 = 'Automatic Cleaning'; 10 = 'SMART Notification'; 11 = 'Supports Dual Sided Media'; - 12 = 'Predismount Eject Not Required' + 12 = 'Predismount Eject Not Required'; } +<################################################################################################## +################# /lib/provider/cpu.psm1 ########################################################## +##################################################################################################> + [hashtable]$CPUArchitecture = @{ 0='x86'; 1='MIPS'; @@ -100,122 +113,122 @@ } [hashtable]$CPUStatusInfo = @{ - 1='Other' - 2='Unknown' - 3='Enabled' - 4='Disabled' - 5='Not Applicable' + 1='Other'; + 2='Unknown'; + 3='Enabled'; + 4='Disabled'; + 5='Not Applicable'; } [hashtable]$CPUFamily = @{ - 1='Other' - 2='Unknown' - 3='8086' - 4='80286' - 5='80386' - 6='80486' - 7='8087' - 8='80287' - 9='80387' - 10='80487' - 11='Pentium(R) brand' - 12='Pentium(R) Pro' - 13='Pentium(R) II' - 14='Pentium(R) processor with MMX(TM) technology' - 15='Celeron(TM)' - 16='Pentium(R) II Xeon(TM)' - 17='Pentium(R) III' - 18='M1 Family' - 19='M2 Family' - 24='K5 Family' - 25='K6 Family' - 26='K6-2' - 27='K6-3' - 28='AMD Athlon(TM) Processor Family' - 29='AMD(R) Duron(TM) Processor' - 30='AMD29000 Family' - 31='K6-2+' - 32='Power PC Family' - 33='Power PC 601' - 34='Power PC 603' - 35='Power PC 603+' - 36='Power PC 604' - 37='Power PC 620' - 38='Power PC X704' - 39='Power PC 750' - 48='Alpha Family' - 49='Alpha 21064' - 50='Alpha 21066' - 51='Alpha 21164' - 52='Alpha 21164PC' - 53='Alpha 21164a' - 54='Alpha 21264' - 55='Alpha 21364' - 64='MIPS Family' - 65='MIPS R4000' - 66='MIPS R4200' - 67='MIPS R4400' - 68='MIPS R4600' - 69='MIPS R10000' - 80='SPARC Family' - 81='SuperSPARC' - 82='microSPARC II' - 83='microSPARC IIep' - 84='UltraSPARC' - 85='UltraSPARC II' - 86='UltraSPARC IIi' - 87='UltraSPARC III' - 88='UltraSPARC IIIi' - 96='68040' - 97='68xxx Family' - 98='68000' - 99='68010' - 100='68020' - 101='68030' - 112='Hobbit Family' - 120='Crusoe(TM) TM5000 Family' - 121='Crusoe(TM) TM3000 Family' - 122='Efficeon(TM) TM8000 Family' - 128='Weitek' - 130='Itanium(TM) Processor' - 131='AMD Athlon(TM) 64 Processor Family' - 132='AMD Opteron(TM) Family' - 144='PA-RISC Family' - 145='PA-RISC 8500' - 146='PA-RISC 8000' - 147='PA-RISC 7300LC' - 148='PA-RISC 7200' - 149='PA-RISC 7100LC' - 150='PA-RISC 7100' - 160='V30 Family' - 176='Pentium(R) III Xeon(TM)' - 177='Pentium(R) III Processor with Intel(R) SpeedStep(TM) Technology' - 178='Pentium(R) 4' - 179='Intel(R) Xeon(TM)' - 180='AS400 Family' - 181='Intel(R) Xeon(TM) processor MP' - 182='AMD AthlonXP(TM) Family' - 183='AMD AthlonMP(TM) Family' - 184='Intel(R) Itanium(R) 2' - 185='Intel Pentium M Processor' - 190='K7' - 200='IBM390 Family' - 201='G4' - 202='G5' - 203='G6' - 204='z/Architecture base' - 250='i860' - 251='i960' - 260='SH-3' - 261='SH-4' - 280='ARM' - 281='StrongARM' - 300='6x86' - 301='MediaGX' - 302='MII' - 320='WinChip' - 350='DSP' - 500='Video Processor' + 1='Other'; + 2='Unknown'; + 3='8086'; + 4='80286'; + 5='80386'; + 6='80486'; + 7='8087'; + 8='80287'; + 9='80387'; + 10='80487'; + 11='Pentium(R) brand'; + 12='Pentium(R) Pro'; + 13='Pentium(R) II'; + 14='Pentium(R) processor with MMX(TM) technology'; + 15='Celeron(TM)'; + 16='Pentium(R) II Xeon(TM)'; + 17='Pentium(R) III'; + 18='M1 Family'; + 19='M2 Family'; + 24='K5 Family'; + 25='K6 Family'; + 26='K6-2'; + 27='K6-3'; + 28='AMD Athlon(TM) Processor Family'; + 29='AMD(R) Duron(TM) Processor'; + 30='AMD29000 Family'; + 31='K6-2+'; + 32='Power PC Family'; + 33='Power PC 601'; + 34='Power PC 603'; + 35='Power PC 603+'; + 36='Power PC 604'; + 37='Power PC 620'; + 38='Power PC X704'; + 39='Power PC 750'; + 48='Alpha Family'; + 49='Alpha 21064'; + 50='Alpha 21066'; + 51='Alpha 21164'; + 52='Alpha 21164PC'; + 53='Alpha 21164a'; + 54='Alpha 21264'; + 55='Alpha 21364'; + 64='MIPS Family'; + 65='MIPS R4000'; + 66='MIPS R4200'; + 67='MIPS R4400'; + 68='MIPS R4600'; + 69='MIPS R10000'; + 80='SPARC Family'; + 81='SuperSPARC'; + 82='microSPARC II'; + 83='microSPARC IIep'; + 84='UltraSPARC'; + 85='UltraSPARC II'; + 86='UltraSPARC IIi'; + 87='UltraSPARC III'; + 88='UltraSPARC IIIi'; + 96='68040'; + 97='68xxx Family'; + 98='68000'; + 99='68010'; + 100='68020'; + 101='68030'; + 112='Hobbit Family'; + 120='Crusoe(TM) TM5000 Family'; + 121='Crusoe(TM) TM3000 Family'; + 122='Efficeon(TM) TM8000 Family'; + 128='Weitek'; + 130='Itanium(TM) Processor'; + 131='AMD Athlon(TM) 64 Processor Family'; + 132='AMD Opteron(TM) Family'; + 144='PA-RISC Family'; + 145='PA-RISC 8500'; + 146='PA-RISC 8000'; + 147='PA-RISC 7300LC'; + 148='PA-RISC 7200'; + 149='PA-RISC 7100LC'; + 150='PA-RISC 7100'; + 160='V30 Family'; + 176='Pentium(R) III Xeon(TM)'; + 177='Pentium(R) III Processor with Intel(R) SpeedStep(TM) Technology'; + 178='Pentium(R) 4'; + 179='Intel(R) Xeon(TM)'; + 180='AS400 Family'; + 181='Intel(R) Xeon(TM) processor MP'; + 182='AMD AthlonXP(TM) Family'; + 183='AMD AthlonMP(TM) Family'; + 184='Intel(R) Itanium(R) 2'; + 185='Intel Pentium M Processor'; + 190='K7'; + 200='IBM390 Family'; + 201='G4'; + 202='G5'; + 203='G6'; + 204='z/Architecture base'; + 250='i860'; + 251='i960'; + 260='SH-3'; + 261='SH-4'; + 280='ARM'; + 281='StrongARM'; + 300='6x86'; + 301='MediaGX'; + 302='MII'; + 320='WinChip'; + 350='DSP'; + 500='Video Processor'; } [hashtable]$CPUConfigManagerErrorCode = @{ @@ -277,15 +290,109 @@ 21='Quiesced'; } -[hashtable]$ProviderEnums = @{ +[hashtable]$CPUPowerManagementCapabilities = @{ + 0='Unknown'; + 1='Not Supported'; + 2='Disabled'; + 3='Enabled'; +} + +[hashtable]$MemoryFormFactor = @{ + 0='Unknown'; + 1= 'Other'; + 2= 'SIP'; + 3= 'DIP'; + 4= 'ZIP'; + 5= 'SOJ'; + 6= 'Proprietary'; + 7= 'SIMM'; + 8= 'DIMM'; + 9= 'TSOP'; + 10= 'PGA'; + 11= 'RIMM'; + 12= 'SODIMM'; + 13= 'SRIMM'; + 14= 'SMD'; + 15= 'SSMP'; + 16= 'QFP'; + 17= 'TQFP'; + 18= 'SOIC'; + 19= 'LCC'; + 20= 'PLCC'; + 21= 'BGA'; + 22= 'FPBGA'; + 23= 'LGA'; +} + +[hashtable]$MemoryInterleavePosition = @{ + 0= 'Noninterleaved'; + 1= 'First position'; + 2= 'Second position'; +} + +[hashtable]$MemoryMemoryType = @{ + 0= 'Unknown'; + 1= 'Other'; + 2= 'DRAM'; + 3= 'Synchronous DRAM'; + 4= 'Cache DRAM'; + 5= 'EDO'; + 6= 'EDRAM'; + 7= 'VRAM'; + 8= 'SRAM'; + 9= 'RAM'; + 10= 'ROM'; + 11= 'Flash'; + 12='EEPROM'; + 13= 'FEPROM'; + 14= 'EPROM'; + 15= 'CDRAM'; + 16= '3DRAM'; + 17= 'SDRAM'; + 18= 'SGRAM'; + 19= 'RDRAM'; + 20= 'DDR'; + 21= 'DDR2'; + 22= 'DDR2 FB-DIMM'; + 23= 'DDR2—FB-DIMM,May not be available; see note above.'; + 24= 'DDR3—May not be available; see note above.'; + 25= 'FBD2'; +} + +[hashtable]$MemoryTypeDetail = @{ + 1= 'Reserved'; + 2= 'Other'; + 4= 'Unknown'; + 8= 'Fast-paged'; + 16= 'Static column'; + 32= 'Pseudo-static'; + 64= 'RAMBUS'; + 128= 'Synchronous'; + 256= 'CMOS'; + 512= 'EDO'; + 1024= 'Window DRAM'; + 2048= 'Cache DRAM'; + 4096= 'Non-volatile'; +} + +[hashtable]$ProviderEnums = @{ + #/lib/provider/bios.psm1 BiosCharacteristics = $BiosCharacteristics; + #/lib/provider/disks.psm1 DiskCapabilities = $DiskCapabilities; + #/lib/provider/cpu.psm1 CPUArchitecture = $CPUArchitecture; CPUProcessorType = $CPUProcessorType; CPUStatusInfo = $CPUStatusInfo; CPUFamily = $CPUFamily; CPUConfigManagerErrorCode = $CPUConfigManagerErrorCode; CPUAvailability = $CPUAvailability; + CPUPowerManagementCapabilities = $CPUPowerManagementCapabilities; + #/lib/provider/memory.psm1 + MemoryFormFactor = $MemoryFormFactor; + MemoryInterleavePosition = $MemoryInterleavePosition; + MemoryMemoryType = $MemoryMemoryType; + MemoryTypeDetail = $MemoryTypeDetail; } Export-ModuleMember -Variable @('ProviderEnums'); \ No newline at end of file diff --git a/lib/provider/memory.psm1 b/lib/provider/memory.psm1 new file mode 100644 index 0000000..da6edd0 --- /dev/null +++ b/lib/provider/memory.psm1 @@ -0,0 +1,196 @@ +Import-Module $IncludeDir\provider\enums; + +<################################################################################################## +################# Runspace "Show-Icinga{Memory}" ################################################## +##################################################################################################> +function Show-IcingaMemoryData () +{ + + $MEMInformation = Get-CimInstance Win32_PhysicalMemory; + + [hashtable]$MEMData = @{}; + + foreach($id in $MEMInformation) { + $MEMData.Add( + $id.tag.trim("Physical Memory"), @{ + 'Caption' = $id.Name; + 'Description' = $id.Description; + 'Name' = $id.Name; + 'InstallDate' = $id.InstallDate; + 'Status' = $id.Status + 'CreationClassName'= $id.CreationClassName + 'Manufacturer'= $id.Manufacturer + 'Model'= $id.Model + 'OtherIdentifyingInfo'= $id.OtherIdentifyingInfo + 'PartNumber'= $id.PartNumber + 'PoweredOn'= $id.PoweredOn + 'SerialNumber'= $id.SerialNumber + 'SKU'= $id.SKU + 'Tag'= $id.Tag + 'Version'= $id.Version + 'HotSwappable'= $id.HotSwappable + 'Removable'= $id.Removable + 'Replaceable'= $id.Replaceable + 'FormFactor'= $id.FormFactor + 'BankLabel'= $id.BankLabel + 'Capacity'= $id.Capacity + 'DataWidth'= $id.DataWidth + 'InterleavePosition'= $id.InterleavePosition + 'MemoryType'= $id.MemoryType + 'PositionInRow'= $id.PositionInRow + 'Speed'= $id.Speed + 'TotalWidth'= $id.TotalWidth + 'Attributes'= $id.Attributes + 'ConfiguredClockSpeed'= $id.ConfiguredClockSpeed + 'ConfiguredVoltage'= $id.ConfiguredVoltage + 'DeviceLocator'= $id.DeviceLocator + 'InterleaveDataDepth'= $id.InterleaveDataDepth + 'MaxVoltage'= $id.MaxVoltage + 'MinVoltage'= $id.MinVoltage + 'SMBIOSMemoryType'= $id.SMBIOSMemoryType + 'TypeDetail'= $id.TypeDetail + 'PSComputerName'= $id.PSComputerName + } + ); + } + return $MEMData; +} +<################################################################################################## +################# Runspace "Get-Icinga{Memory}" ################################################### +##################################################################################################> +function Get-IcingaMemory () +{ + <# Collects the most important Memory informations, + e.g. name, version, manufacturer#> + $MEMInformation = Get-CimInstance Win32_PhysicalMemory; + + [hashtable]$MEMData = @{}; + + foreach($id in $MEMInformation) { + $MEMData.Add( + $id.tag.trim("Physical Memory"), @{ + 'metadata' = @{ + 'Caption' = $id.Name; + 'Description'= $id.Description; + 'Manufacturer'= $id.Manufacturer; + 'Model'= $id.Model; + 'OtherIdentifyingInfo'= $id.OtherIdentifyingInfo; + 'PartNumber'= $id.PartNumber; + 'SerialNumber'= $id.SerialNumber; + 'Tag'= $id.Tag; + 'SMBIOSMemoryType'= $id.SMBIOSMemoryType; + 'DeviceLocator' = $id.DeviceLocator; + 'PositionInRow' = $id.PositionInRow; + 'Version' = $id.Version; + 'PoweredOn' = $id.PoweredOn; + 'Status' = $id.Status; + 'InstallDate' = $id.InstallDate; + 'BankLabel' = $id.BankLabel; + 'InterleaveDataDepth' = $id.InterleaveDataDepth; + 'Attributes' = $id.Attributes; + 'Replaceable' = $id.Replaceable; + 'Removable' = $id.Removable; + 'HotSwappable' = $id.HotSwappable; + 'FormFactor' = @{ + 'raw' = $id.FormFactor; + 'value' = $ProviderEnums.MemoryFormFactor[[int]$id.FormFactor]; + }; + 'InterleavePosition' = @{ + 'raw' = $id.InterleavePosition; + 'value' = $ProviderEnums.MemoryInterleavePosition[[int]$id.InterleavePosition]; + }; + 'MemoryType' = @{ + 'raw' = $id.MemoryType; + 'value' = $ProviderEnums.MemoryMemoryType[[int]$id.MemoryType]; + }; + 'TypeDetail' = @{ + 'raw' = $id.TypeDetail; + 'value' = $ProviderEnums.MemoryTypeDetail[[int]$id.TypeDetail]; + }; + }; + 'specs' = @{ + 'MaxVoltage' = $id.MaxVoltage; + 'MinVoltage' = $id.MinVoltage; + 'ConfiguredVoltage' = $id.ConfiguredVoltage; + 'ConfiguredClockSpeed' = $id.ConfiguredClockSpeed; + 'TotalWidth' = $id.TotalWidth; + 'DataWidth' = $id.DataWidth; + 'Speed' = $id.Speed; + 'Capacity' = $id.Capacity; + } + } + ); + } + + return $MEMData; +} + +function Get-IcingaMemoryInformation() +{ + param( + [string]$Parameter + ); + $MEMInformation = Get-CimInstance Win32_PhysicalMemory; + [hashtable]$MEMData = @{}; + + foreach ($id in $MEMInformation) { + $MEMData.Add($id.tag.trim("Physical Memory"), $id.$Parameter); + } + + return $MEMData; +} +function Get-IcingaMemoryMaxVoltage() +{ + $MemoryMaxVoltage = Get-IcingaMemoryInformation -Parameter MaxVoltage; + + return @{'value' = $MemoryMaxVoltage; 'name' = 'MaxVoltage'}; +} + +function Get-IcingaMemoryMinVoltage() +{ + $MemoryMinVoltage = Get-IcingaMemoryInformation -Parameter MinVoltage; + + return @{'value' = $MemoryMinVoltage; 'name' = 'MinVoltage'}; +} + +function Get-IcingaMemoryConfiguredVoltage() +{ + $MemoryConfiguredVoltage = Get-IcingaMemoryInformation -Parameter ConfiguredVoltage; + + return @{'value' = $MemoryConfiguredVoltage; 'name' = 'ConfiguredVoltage'}; +} + +function Get-IcingaMemoryConfiguredClockSpeed() +{ + $MemoryConfiguredClockSpeed = Get-IcingaMemoryInformation -Parameter ConfiguredClockSpeed; + + return @{'value' = $MemoryConfiguredClockSpeed; 'name' = 'ConfiguredClockSpeed'}; +} + +function Get-IcingaMemoryTotalWidth() +{ + $MemoryTotalWidth = Get-IcingaMemoryInformation -Parameter TotalWidth; + + return @{'value' = $MemoryTotalWidth; 'name' = 'TotalWidth'}; +} + +function Get-IcingaMemoryDataWidth() +{ + $MemoryDataWidth = Get-IcingaMemoryInformation -Parameter DataWidth; + + return @{'value' = $MemoryDataWidth; 'name' = 'DataWidth'}; +} + +function Get-IcingaMemorySpeed() +{ + $MemorySpeed = Get-IcingaMemoryInformation -Parameter Speed; + + return @{'value' = $MemorySpeed; 'name' = 'Speed'}; +} + +function Get-IcingaMemoryCapacity() +{ + $MemoryCapacity = Get-IcingaMemoryInformation -Parameter Capacity; + + return @{'value' = $MemoryCapacity; 'name' = 'Capacity'}; +} \ No newline at end of file From 97ee39486a681d750e4f00ffd2d4a1da00f68352 Mon Sep 17 00:00:00 2001 From: Crited Date: Mon, 22 Jul 2019 07:32:52 +0200 Subject: [PATCH 06/10] Added Process.psm1, Added Services.psm1; Fixed previous concept errors --- lib/provider/cpu.psm1 | 143 ++++++++++++++++++--------------- lib/provider/disks.psm1 | 42 ++++++---- lib/provider/enums.psm1 | 4 + lib/provider/memory.psm1 | 160 ++++++++++++++++++------------------- lib/provider/process.psm1 | 124 ++++++++++++++++++++++++++++ lib/provider/services.psm1 | 61 ++++++++++++++ 6 files changed, 374 insertions(+), 160 deletions(-) create mode 100644 lib/provider/process.psm1 create mode 100644 lib/provider/services.psm1 diff --git a/lib/provider/cpu.psm1 b/lib/provider/cpu.psm1 index bdef95a..986a9f9 100644 --- a/lib/provider/cpu.psm1 +++ b/lib/provider/cpu.psm1 @@ -30,75 +30,74 @@ function Get-IcingaCPUs() $CPUInformation = Get-CimInstance Win32_Processor; [hashtable]$CPUData = @{}; - foreach ($id in $CPUInformation.DeviceID) { - $id=$id.trim('CPU'); + foreach ($cpu in $CPUInformation) { $CPUData.Add( - $id, @{ + $cpu.DeviceID.trim('CPU'), @{ 'metadata' = @{ - 'Name' = $CPUInformation.Name; - 'DeviceID' = $CPUInformation.DeviceID; - 'ProcessorID' = $CPUInformation.ProcessorId; - 'UniqueID' = $CPUInformation.UniqueId; - 'Description' = $CPUInformation.Description; - 'OtherFamilyDescription' = $CPUInformation.OtherFamilyDescription; - 'Caption' = $CPUInformation.Caption; - 'Version' = $CPUInformation.Version; - 'SerialNumber' = $CPUInformation.SerialNumber; - 'Manufacturer' = $CPUInformation.Manufacturer; - 'NumberOfCores' = $CPUInformation.NumberOfCores; - 'PartNumber' = $CPUInformation.PartNumber; - 'Status' = $CPUInformation.Status; - 'CPUStatus' = $CPUInformation.CpuStatus; - 'Revision' = $CPUInformation.Revision; - 'NumberOfLogicalProcessors' = $CPUInformation.NumberOfLogicalProcessors; - 'Level'= $CPUInformation.Level; - 'AddressWidth' = $CPUInformation.AddressWidth; - 'Stepping' = $CPUInformation.Stepping; - 'SocketDesignation' = $CPUInformation.SocketDesignation; + 'Name' = $cpu.Name; + 'DeviceID' = $cpu.DeviceID; + 'ProcessorID' = $cpu.ProcessorId; + 'UniqueID' = $cpu.UniqueId; + 'Description' = $cpu.Description; + 'OtherFamilyDescription' = $cpu.OtherFamilyDescription; + 'Caption' = $cpu.Caption; + 'Version' = $cpu.Version; + 'SerialNumber' = $cpu.SerialNumber; + 'Manufacturer' = $cpu.Manufacturer; + 'NumberOfCores' = $cpu.NumberOfCores; + 'PartNumber' = $cpu.PartNumber; + 'Status' = $cpu.Status; + 'CPUStatus' = $cpu.CpuStatus; + 'Revision' = $cpu.Revision; + 'NumberOfLogicalProcessors' = $cpu.NumberOfLogicalProcessors; + 'Level'= $cpu.Level; + 'AddressWidth' = $cpu.AddressWidth; + 'Stepping' = $cpu.Stepping; + 'SocketDesignation' = $cpu.SocketDesignation; 'Family' = @{ - 'raw' = $CPUInformation.Family; - 'value' = $ProviderEnums.CPUFamily[[int]$CPUInformation.Family]; + 'raw' = $cpu.Family; + 'value' = $ProviderEnums.CPUFamily[[int]$cpu.Family]; }; 'Architecture' = @{ - 'raw' = $CPUInformation.Architecture; - 'value' = $ProviderEnums.CPUArchitecture[[int]$CPUInformation.Architecture]; + 'raw' = $cpu.Architecture; + 'value' = $ProviderEnums.CPUArchitecture[[int]$cpu.Architecture]; }; 'ProcessorType' = @{ - 'raw' = $CPUInformation.ProcessorType; - 'value' = $ProviderEnums.CPUProcessorType[[int]$CPUInformation.ProcessorType]; + 'raw' = $cpu.ProcessorType; + 'value' = $ProviderEnums.CPUProcessorType[[int]$cpu.ProcessorType]; }; 'StatusInfo' = @{ - 'raw' = $CPUInformation.StatusInfo; - 'value' = $ProviderEnums.CPUStatusInfo[[int]$CPUInformation.StatusInfo]; + 'raw' = $cpu.StatusInfo; + 'value' = $ProviderEnums.CPUStatusInfo[[int]$cpu.StatusInfo]; }; 'Availability' = @{ - 'raw' = $CPUInformation.Availability; - 'value' = $ProviderEnums.CPUAvailability[[int]$CPUInformation.Availability]; + 'raw' = $cpu.Availability; + 'value' = $ProviderEnums.CPUAvailability[[int]$cpu.Availability]; }; 'PowerManagementCapabilities' = @{ - 'raw' = $CPUInformation.PowerManagementCapabilities; - 'value' = $ProviderEnums.CPUPowerManagementCapabilities[[int]$CPUInformation.PowerManagementCapabilities]; + 'raw' = $cpu.PowerManagementCapabilities; + 'value' = $ProviderEnums.CPUPowerManagementCapabilities[[int]$cpu.PowerManagementCapabilities]; } }; 'errors' = @{ - 'LastErrorCode' = $CPUInformation.LastErrorCode; - 'ErrorCleared' = $CPUInformation.ErrorCleared; - 'ErrorDescription' = $CPUInformation.ErrorDescription; + 'LastErrorCode' = $cpu.LastErrorCode; + 'ErrorCleared' = $cpu.ErrorCleared; + 'ErrorDescription' = $cpu.ErrorDescription; 'ConfigManagerErrorCode' = @{ - 'raw' = [int]$CPUInformation.ConfigManagerErrorCode; - 'value' = $ProviderEnums.CPUConfigManagerErrorCode.([int]$CPUInformation.ConfigManagerErrorCode); + 'raw' = [int]$cpu.ConfigManagerErrorCode; + 'value' = $ProviderEnums.CPUConfigManagerErrorCode.([int]$cpu.ConfigManagerErrorCode); } }; 'specs' = @{ - 'LoadPercentage' = $CPUInformation.LoadPercentage; - 'CurrentVoltage' = $CPUInformation.CurrentVoltage; - 'ThreadCount' = $CPUInformation.ThreadCount; - 'L3CacheSize' = $CPUInformation.L3CacheSize; - 'L2CacheSpeed' = $CPUInformation.L2CacheSpeed; - 'L2CacheSize' = $CPUInformation.L2CacheSize; - 'VoltageCaps' = $CPUInformation.VoltageCaps; - 'CurrentClockSpeed' = $CPUInformation.CurrentClockSpeed; + 'LoadPercentage' = $cpu.LoadPercentage; + 'CurrentVoltage' = $cpu.CurrentVoltage; + 'ThreadCount' = $cpu.ThreadCount; + 'L3CacheSize' = $cpu.L3CacheSize; + 'L2CacheSpeed' = $cpu.L2CacheSpeed; + 'L2CacheSize' = $cpu.L2CacheSize; + 'VoltageCaps' = $cpu.VoltageCaps; + 'CurrentClockSpeed' = $cpu.CurrentClockSpeed; } } ); @@ -117,8 +116,8 @@ function Get-IcingaCPUInformation() $CPUInformation = Get-CimInstance Win32_Processor; [hashtable]$CPUData = @{}; - foreach ($id in $CPUInformation.DeviceID) { - $CPUData.Add($id.trim('CPU'), $CPUInformation.$Parameter); + foreach ($cpu in $CPUInformation) { + $CPUData.Add($cpu.DeviceID.trim('CPU'), $cpu.$Parameter); } return $CPUData; @@ -137,12 +136,11 @@ function Get-IcingaCPUInformationWithEnums() [hashtable]$CPUData = @{}; - foreach ($id in $CPUInformation.DeviceID) { - $id=$id.trim('CPU'); + foreach ($cpu in $CPUInformation) { $CPUData.Add( - $id, @{ - 'raw' = $CPUInformation.$Parameter; - 'value' = $ProviderEnums."$Prefix$Parameter"[[int]$CPUInformation.$Parameter] + $cpu.DeviceID.trim('CPU'), @{ + 'raw' = $cpu.$Parameter; + 'value' = $ProviderEnums."$Prefix$Parameter"[[int]$cpu.$Parameter] } ); } @@ -154,17 +152,16 @@ function Get-IcingaCPUErrors() $CPUInformation = Get-CimInstance Win32_Processor; [hashtable]$CPUData = @{}; - foreach ($id in $CPUInformation.DeviceID) { - $id=$id.trim('CPU'); + foreach ($cpu in $CPUInformation) { $CPUData.Add( - $id, @{ + $cpu.trim('CPU'), @{ 'errors' = @{ - 'LastErrorCode' = $CPUInformation.LastErrorCode; - 'ErrorCleared' = $CPUInformation.ErrorCleared; - 'ErrorDescription' = $CPUInformation.ErrorDescription; + 'LastErrorCode' = $cpu.LastErrorCode; + 'ErrorCleared' = $cpu.ErrorCleared; + 'ErrorDescription' = $cpu.ErrorDescription; 'ConfigManagerErrorCode' = @{ - 'raw' = [int]$CPUInformation.ConfigManagerErrorCode; - 'value' = $ProviderEnums.CPUConfigManagerErrorCode.([int]$CPUInformation.ConfigManagerErrorCode); + 'raw' = [int]$cpu.ConfigManagerErrorCode; + 'value' = $ProviderEnums.CPUConfigManagerErrorCode.([int]$cpu.ConfigManagerErrorCode); } } } @@ -283,4 +280,24 @@ function Get-IcingaCPUNumberOfLogicalProcessors() $CPUNumberOfLogicalProcessors = Get-IcingaCPUInformation -Parameter NumberOfLogicalProcessors; return @{'value' = $CPUNumberOfLogicalProcessors; 'name' = 'NumberOfLogicalProcessors'}; +} + +function Get-IcingaCPUCount() +{ + <# Collects the most important CPU informations, + e.g. name, version, manufacturer#> + $CPUInformation = Get-CimInstance Win32_Processor; + + foreach ($cpu in $CPUInformation) { + $NumberOfCoresValue += $cpu.NumberOfCores; + $NumberOfLogicalProcessorsValue += $cpu.NumberOfLogicalProcessors; + $ThreadCountValue += $cpu.ThreadCount; + } + + If (($NumberOfCoresValue -ge $NumberOfLogicalProcessorsValue) -and ($NumberOfCoresValue -ge $ThreadCountValue)) { + return $NumberOfCoresValue; + } elseif ($NumberOfLogicalProcessorsValue -ge $ThreadCountValue) { + return $NumberOfLogicalProcessorsValue; + } + return $ThreadCountValue; } \ No newline at end of file diff --git a/lib/provider/disks.psm1 b/lib/provider/disks.psm1 index d689a33..eed30ec 100644 --- a/lib/provider/disks.psm1 +++ b/lib/provider/disks.psm1 @@ -106,15 +106,17 @@ function Get-IcingaDiskInformation() $DiskInformation = Get-CimInstance Win32_DiskDrive; [hashtable]$DiskData = @{}; - foreach ($id in $DiskInformation.DeviceID) { - $id = $id.trimstart(".\PHYSICALDRVE"); - $DiskData.Add($id.trim(), $DiskInformation.$Parameter); + foreach ($disk in $DiskInformation) { + $DiskData.Add($disk.DeviceID.trimstart(".\PHYSICALDRVE"), $disk.$Parameter); } return $DiskData; } function Get-IcingaDiskPartitions() { + param( + $Disk + ); <# Fetches all the most important informations regarding partitions e.g. physical disk; partition, size , also collects partition information for Get-IcingaDisks #> @@ -137,7 +139,15 @@ function Get-IcingaDiskPartitions() $diskPartition = $diskPartition.trim("Partition #"); $diskDisk = $diskDisk.trim("Disk #"); + + If ([string]::IsNullOrEmpty($Disk) -eq $FALSE) { + If ([int]$Disk -ne [int]$diskDisk) { + continue; + } + } + $diskPartitionSize = Get-Partition -DriveLetter $driveLetter; + $PartitionDiskByDriveLetter.Add( $driveLetter, @{ @@ -182,8 +192,8 @@ function Get-IcingaDiskCapabilities $DiskInformation = Get-CimInstance Win32_DiskDrive; [hashtable]$DiskCapabilities = @{}; - foreach ($id in $DiskInformation.Capabilities) { - $DiskCapabilities.Add([int]$id, $ProviderEnums.DiskCapabilities.([int]$id)); + foreach ($capabilities in $DiskInformation.Capabilities) { + $DiskCapabilities.Add([int]$capabilities, $ProviderEnums.DiskCapabilities.([int]$capabilities)); } return @{'value' = $DiskCapabilities; 'name' = 'Capabilities'}; @@ -231,23 +241,21 @@ function Get-IcingaDisks { e.g. size, model, sectors, cylinders Is dependent on Get-IcingaDiskPartitions#> $DiskInformation = Get-CimInstance Win32_DiskDrive; - $diskPartitionInformation = Get-IcingaDiskPartitions; [hashtable]$DiskData = @{}; - foreach ($id in $DiskInformation.DeviceID) { - [int]$id = $id.trimstart(".\PHYSICALDRVE"); - + foreach ($disk in $DiskInformation) { + $diskID = $disk.DeviceID.trimstart(".\PHYSICALDRVE"); $DiskData.Add( - $id, @{ + $diskID, @{ 'metadata' = @{ - 'Size' = $DiskInformation.Size; - 'Model' = $DiskInformation.Model; - 'Name' = $DiskInformation.Name.trim('.\'); - 'Manufacturer' = $DiskInformation.Manufacturer; - 'Cylinder' = $DiskInformation.TotalCylinders; - 'Sectors' = $DiskInformation.TotalSectors + 'Size' = $disk.Size; + 'Model' = $disk.Model; + 'Name' = $disk.Name.trim('.\'); + 'Manufacturer' = $disk.Manufacturer; + 'Cylinder' = $disk.TotalCylinders; + 'Sectors' = $disk.TotalSectors }; - 'partitions' = $diskPartitionInformation + 'partitions' = (Get-IcingaDiskPartitions -Disk $diskID); } ); } diff --git a/lib/provider/enums.psm1 b/lib/provider/enums.psm1 index 6903ec0..52faa73 100644 --- a/lib/provider/enums.psm1 +++ b/lib/provider/enums.psm1 @@ -297,6 +297,10 @@ 3='Enabled'; } +<################################################################################################## +################# /lib/provider/memory.psm1 ####################################################### +##################################################################################################> + [hashtable]$MemoryFormFactor = @{ 0='Unknown'; 1= 'Other'; diff --git a/lib/provider/memory.psm1 b/lib/provider/memory.psm1 index da6edd0..6e17fc0 100644 --- a/lib/provider/memory.psm1 +++ b/lib/provider/memory.psm1 @@ -10,46 +10,46 @@ function Show-IcingaMemoryData () [hashtable]$MEMData = @{}; - foreach($id in $MEMInformation) { + foreach($memory in $MEMInformation) { $MEMData.Add( - $id.tag.trim("Physical Memory"), @{ - 'Caption' = $id.Name; - 'Description' = $id.Description; - 'Name' = $id.Name; - 'InstallDate' = $id.InstallDate; - 'Status' = $id.Status - 'CreationClassName'= $id.CreationClassName - 'Manufacturer'= $id.Manufacturer - 'Model'= $id.Model - 'OtherIdentifyingInfo'= $id.OtherIdentifyingInfo - 'PartNumber'= $id.PartNumber - 'PoweredOn'= $id.PoweredOn - 'SerialNumber'= $id.SerialNumber - 'SKU'= $id.SKU - 'Tag'= $id.Tag - 'Version'= $id.Version - 'HotSwappable'= $id.HotSwappable - 'Removable'= $id.Removable - 'Replaceable'= $id.Replaceable - 'FormFactor'= $id.FormFactor - 'BankLabel'= $id.BankLabel - 'Capacity'= $id.Capacity - 'DataWidth'= $id.DataWidth - 'InterleavePosition'= $id.InterleavePosition - 'MemoryType'= $id.MemoryType - 'PositionInRow'= $id.PositionInRow - 'Speed'= $id.Speed - 'TotalWidth'= $id.TotalWidth - 'Attributes'= $id.Attributes - 'ConfiguredClockSpeed'= $id.ConfiguredClockSpeed - 'ConfiguredVoltage'= $id.ConfiguredVoltage - 'DeviceLocator'= $id.DeviceLocator - 'InterleaveDataDepth'= $id.InterleaveDataDepth - 'MaxVoltage'= $id.MaxVoltage - 'MinVoltage'= $id.MinVoltage - 'SMBIOSMemoryType'= $id.SMBIOSMemoryType - 'TypeDetail'= $id.TypeDetail - 'PSComputerName'= $id.PSComputerName + $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 } ); } @@ -66,57 +66,57 @@ function Get-IcingaMemory () [hashtable]$MEMData = @{}; - foreach($id in $MEMInformation) { + foreach($memory in $MEMInformation) { $MEMData.Add( - $id.tag.trim("Physical Memory"), @{ + $memory.tag.trim("Physical Memory"), @{ 'metadata' = @{ - 'Caption' = $id.Name; - 'Description'= $id.Description; - 'Manufacturer'= $id.Manufacturer; - 'Model'= $id.Model; - 'OtherIdentifyingInfo'= $id.OtherIdentifyingInfo; - 'PartNumber'= $id.PartNumber; - 'SerialNumber'= $id.SerialNumber; - 'Tag'= $id.Tag; - 'SMBIOSMemoryType'= $id.SMBIOSMemoryType; - 'DeviceLocator' = $id.DeviceLocator; - 'PositionInRow' = $id.PositionInRow; - 'Version' = $id.Version; - 'PoweredOn' = $id.PoweredOn; - 'Status' = $id.Status; - 'InstallDate' = $id.InstallDate; - 'BankLabel' = $id.BankLabel; - 'InterleaveDataDepth' = $id.InterleaveDataDepth; - 'Attributes' = $id.Attributes; - 'Replaceable' = $id.Replaceable; - 'Removable' = $id.Removable; - 'HotSwappable' = $id.HotSwappable; + 'Caption' = $memory.Name; + 'Description'= $memory.Description; + 'Manufacturer'= $memory.Manufacturer; + 'Model'= $memory.Model; + 'OtherIdentifyingInfo'= $memory.OtherIdentifyingInfo; + 'PartNumber'= $memory.PartNumber; + 'SerialNumber'= $memory.SerialNumber; + 'Tag'= $memory.Tag; + 'SMBIOSMemoryType'= $memory.SMBIOSMemoryType; + 'DeviceLocator' = $memory.DeviceLocator; + 'PositionInRow' = $memory.PositionInRow; + 'Version' = $memory.Version; + 'PoweredOn' = $memory.PoweredOn; + 'Status' = $memory.Status; + 'InstallDate' = $memory.InstallDate; + 'BankLabel' = $memory.BankLabel; + 'InterleaveDataDepth' = $memory.InterleaveDataDepth; + 'Attributes' = $memory.Attributes; + 'Replaceable' = $memory.Replaceable; + 'Removable' = $memory.Removable; + 'HotSwappable' = $memory.HotSwappable; 'FormFactor' = @{ - 'raw' = $id.FormFactor; - 'value' = $ProviderEnums.MemoryFormFactor[[int]$id.FormFactor]; + 'raw' = $memory.FormFactor; + 'value' = $ProviderEnums.MemoryFormFactor[[int]$memory.FormFactor]; }; 'InterleavePosition' = @{ - 'raw' = $id.InterleavePosition; - 'value' = $ProviderEnums.MemoryInterleavePosition[[int]$id.InterleavePosition]; + 'raw' = $memory.InterleavePosition; + 'value' = $ProviderEnums.MemoryInterleavePosition[[int]$memory.InterleavePosition]; }; 'MemoryType' = @{ - 'raw' = $id.MemoryType; - 'value' = $ProviderEnums.MemoryMemoryType[[int]$id.MemoryType]; + 'raw' = $memory.MemoryType; + 'value' = $ProviderEnums.MemoryMemoryType[[int]$memory.MemoryType]; }; 'TypeDetail' = @{ - 'raw' = $id.TypeDetail; - 'value' = $ProviderEnums.MemoryTypeDetail[[int]$id.TypeDetail]; + 'raw' = $memory.TypeDetail; + 'value' = $ProviderEnums.MemoryTypeDetail[[int]$memory.TypeDetail]; }; }; 'specs' = @{ - 'MaxVoltage' = $id.MaxVoltage; - 'MinVoltage' = $id.MinVoltage; - 'ConfiguredVoltage' = $id.ConfiguredVoltage; - 'ConfiguredClockSpeed' = $id.ConfiguredClockSpeed; - 'TotalWidth' = $id.TotalWidth; - 'DataWidth' = $id.DataWidth; - 'Speed' = $id.Speed; - 'Capacity' = $id.Capacity; + 'MaxVoltage' = $memory.MaxVoltage; + 'MinVoltage' = $memory.MinVoltage; + 'ConfiguredVoltage' = $memory.ConfiguredVoltage; + 'ConfiguredClockSpeed' = $memory.ConfiguredClockSpeed; + 'TotalWidth' = $memory.TotalWidth; + 'DataWidth' = $memory.DataWidth; + 'Speed' = $memory.Speed; + 'Capacity' = $memory.Capacity; } } ); @@ -133,8 +133,8 @@ function Get-IcingaMemoryInformation() $MEMInformation = Get-CimInstance Win32_PhysicalMemory; [hashtable]$MEMData = @{}; - foreach ($id in $MEMInformation) { - $MEMData.Add($id.tag.trim("Physical Memory"), $id.$Parameter); + foreach ($memory in $MEMInformation) { + $MEMData.Add($memory.tag.trim("Physical Memory"), $memory.$Parameter); } return $MEMData; diff --git a/lib/provider/process.psm1 b/lib/provider/process.psm1 new file mode 100644 index 0000000..26e639f --- /dev/null +++ b/lib/provider/process.psm1 @@ -0,0 +1,124 @@ +Import-Module $IncludeDir\provider\cpu; + +function Add-IcingaProcessPerfData() +{ + param($ProcessList, $ProcessKey, $Process); + + if ($ProcessList.ContainsKey($ProcessKey) -eq $FALSE) { + $ProcessList.Add($ProcessKey, $Process.$ProcessKey); + } else { + $ProcessList[$ProcessKey] += $Process.$ProcessKey; + } +} + +function Get-IcingaProcessData { + + $ProcessInformation = Get-WmiObject Win32_Process; + $ProcessPerfDataList = Get-WmiObject Win32_PerfFormattedData_PerfProc_Process; + $ProcessUniqueList = Get-WmiObject Win32_Process | Select-Object name -unique; + $CPUCoreCount = Get-IcingaCPUCount; + + + [hashtable]$ProcessData = @{}; + [hashtable]$ProcessList = @{}; + [hashtable]$ProcessNamesUnique = @{}; + [hashtable]$ProcessIDsByName = @{}; + #$NumberOfCPUThreads = $Icinga2.System.NumberOfCPUThreads; + + foreach ($process in $ProcessInformation) { + [string]$processName = $process.Name.Replace('.exe', ''); + + if ($ProcessList.ContainsKey($processName) -eq $FALSE) { + $ProcessList.Add($processName, @{ + 'ProcessList' = @{}; + 'PerformanceData' = @{} + }); + } + + $ProcessList[$processName]['ProcessList'].Add( + [string]$process.ProcessID, @{ + 'Name' = $process.Name; + 'ProcessId' = $process.ProcessId; + 'Priority' = $process.Priority; + 'PageFileUsage' = $process.PageFileUsage; + 'ThreadCount' = $process.ThreadCount; + 'KernelModeTime' = $process.KernelModeTime; + 'UserModeTime' = $process.UserModeTime; + 'WorkingSetSize' = $process.WorkingSetSize; + 'CommandLine' = $process.CommandLine; + } + ); + + Add-IcingaProcessPerfData -ProcessList $ProcessList[$processName]['PerformanceData'] -ProcessKey 'ThreadCount' -Process $process; + Add-IcingaProcessPerfData -ProcessList $ProcessList[$processName]['PerformanceData'] -ProcessKey 'PageFileUsage' -Process $process; + Add-IcingaProcessPerfData -ProcessList $ProcessList[$processName]['PerformanceData'] -ProcessKey 'KernelModeTime' -Process $process; + Add-IcingaProcessPerfData -ProcessList $ProcessList[$processName]['PerformanceData'] -ProcessKey 'UserModeTime' -Process $process; + Add-IcingaProcessPerfData -ProcessList $ProcessList[$processName]['PerformanceData'] -ProcessKey 'WorkingSetSize' -Process $process; + } + + foreach ($process in $ProcessPerfDataList) { + if ($process.Name -eq '_Total' -Or $process.Name -eq 'Idle') { + continue; + } + + [string]$processName = $process.Name.Split('#')[0]; + [string]$ProcessId = $process.IDProcess; + + if ($ProcessList.ContainsKey($processName) -eq $FALSE) { + Write-Host 'Unknown Process Name: ' $processName; + continue; + } + + if ($ProcessList[$processName]['ProcessList'].ContainsKey($ProcessId) -eq $FALSE) { + Write-Host 'Unknown Process ID: ' $ProcessId; + continue; + } + + $ProcessList[$processName]['ProcessList'][$ProcessId].Add( + 'WorkingSetPrivate', $process.WorkingSetPrivate + ); + $ProcessList[$processName]['ProcessList'][$ProcessId].Add( + 'PercentProcessorTime', ($process.PercentProcessorTime / $CPUCoreCount) + ); + + Add-IcingaProcessPerfData -ProcessList $ProcessList[$processName]['PerformanceData'] -ProcessKey 'WorkingSetPrivate' -Process $process; + if ($ProcessList[$processName]['PerformanceData'].ContainsKey('PercentProcessorTime') -eq $FALSE) { + $ProcessList[$processName]['PerformanceData'].Add('PercentProcessorTime', ($process.PercentProcessorTime / $CPUCoreCount)); + } else { + $ProcessList[$processName]['PerformanceData']['PercentProcessorTime'] += ($process.PercentProcessorTime / $CPUCoreCount); + } + } + + $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.psm1 new file mode 100644 index 0000000..54724bc --- /dev/null +++ b/lib/provider/services.psm1 @@ -0,0 +1,61 @@ +function Get-IcingaServices() +{ + param ( + [array]$Service + ) + + $ServiceInformation = Get-Service -Name $Service; + + [hashtable]$ServiceData = @{}; + + foreach ($service in $ServiceInformation) { + + [array]$DependentServices = $null; + [array]$DependingServices = $null; + + #Dependent / Child + foreach ($dependency in $service.DependentServices) { + if ($null -eq $DependentServices) { $DependentServices = @(); } + $DependentServices += $dependency.Name; + } + + #Depends / Parent + foreach ($dependency in $service.ServicesDependedOn) { + if ($null -eq $DependingServices) { $DependingServices = @(); } + $DependingServices += $dependency.Name; + } + + $ServiceData.Add( + $service.Name, @{ + 'metadata' = @{ + 'DisplayName' = $service.DisplayName; + 'ServiceName' = $service.ServiceName; + 'Site' = $service.Site; + 'Container' = $service.Container; + 'ServiceHandle' = $service.ServiceHandle; + 'Dependent' = $DependentServices; + 'Depends' = $DependingServices; + }; + 'configuration' = @{ + 'CanPauseAndContinue' = $service.CanPauseAndContinue; + 'CanShutdown' = $service.CanShutdown; + 'CanStop' = $service.CanStop; + 'Status' = @{ + 'raw' = [int]$service.Status; + 'value' = $service.Status; + }; + 'ServiceType' = @{ + 'raw' = [int]$service.ServiceType; + 'value' = $service.ServiceType; + }; + 'ServiceHandle' = $service.ServiceHandle; + 'StartType' = @{ + 'raw' = [int]$service.StartType; + 'value' = $service.StartType; + }; + } + } + ); + } + return $ServiceData; +} \ No newline at end of file From a89c85215b0c7324419dece48082a9947d955fea Mon Sep 17 00:00:00 2001 From: Crited Date: Mon, 22 Jul 2019 10:01:11 +0200 Subject: [PATCH 07/10] 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 From 7ca64c27c7e94a5ce41d59ea3e2d00a113fd517c Mon Sep 17 00:00:00 2001 From: Crited Date: Mon, 22 Jul 2019 15:23:21 +0200 Subject: [PATCH 08/10] Expanded upon Icinga_ProviderWindows.psm1; Minor Changes to other modules regarding structure and comments --- lib/provider/enums/Icinga_ProviderEnums.psm1 | 112 ++++++++++++++++-- .../memory/Icinga_ProviderMemory.psm1 | 2 +- .../windows/Icinga_ProviderWindows.psm1 | 39 +++++- .../windows/Show-IcingaWindowsData.psm1 | 11 ++ 4 files changed, 151 insertions(+), 13 deletions(-) create mode 100644 lib/provider/windows/Show-IcingaWindowsData.psm1 diff --git a/lib/provider/enums/Icinga_ProviderEnums.psm1 b/lib/provider/enums/Icinga_ProviderEnums.psm1 index 52faa73..3818cfc 100644 --- a/lib/provider/enums/Icinga_ProviderEnums.psm1 +++ b/lib/provider/enums/Icinga_ProviderEnums.psm1 @@ -1,6 +1,6 @@ <################################################################################################## -################# /lib/provider/bios.psm1 ######################################################### +################# /lib/provider/bios ############################################################## ##################################################################################################> [hashtable]$BiosCharacteristics = @{ @@ -71,7 +71,7 @@ } <################################################################################################## -################# /lib/provider/disks.psm1 ######################################################## +################# /lib/provider/disks ############################################################# ##################################################################################################> [hashtable]$DiskCapabilities = @{ @@ -91,7 +91,7 @@ } <################################################################################################## -################# /lib/provider/cpu.psm1 ########################################################## +################# /lib/provider/cpu ############################################################### ##################################################################################################> [hashtable]$CPUArchitecture = @{ @@ -298,7 +298,7 @@ } <################################################################################################## -################# /lib/provider/memory.psm1 ####################################################### +################# /lib/provider/memory ############################################################ ##################################################################################################> [hashtable]$MemoryFormFactor = @{ @@ -379,12 +379,104 @@ 4096= 'Non-volatile'; } +<################################################################################################## +################# /lib/provider/Windows ########################################################### +##################################################################################################> + +[hashtable]$WindowsOSProductSuite = @{ + 1= 'Microsoft Small Business Server was once installed, but may have been upgraded to another version of Windows.'; + 2= 'Windows Server 2008 Enterprise is installed.'; + 4= 'Windows BackOffice components are installed.'; + 8= 'Communication Server is installed.'; + 16= 'Terminal Services is installed.'; + 32= 'Microsoft Small Business Server is installed with the restrictive client license.'; + 64= 'Windows Embedded is installed.'; + 128= 'Datacenter edition is installed.'; + 256= 'Terminal Services is installed, but only one interactive session is supported.'; + 512= 'Windows Home Edition is installed.'; + 1024= 'Web Server Edition is installed.'; + 8192= 'Storage Server Edition is installed.'; + 16384= 'Compute Cluster Edition is installed.'; +} + +[hashtable]$WindowsProductType = @{ + 1= 'Work Station'; + 2= 'Domain Controller'; + 3= 'Server'; +} + +[hashtable]$WindowsOSType = @{ + 0= 'Unknown'; + 1= 'Other'; + 2= 'MACROS'; + 3= 'ATTUNIX'; + 4= 'DGUX'; + 5= 'DECNT'; + 6= 'Digital Unix'; + 7= 'OpenVMS' + 8= 'HPUX'; + 9= 'AIX'; + 10= 'MVS'; + 11= 'OS400'; + 12= 'OS/2'; + 13= 'JavaVM'; + 14= 'MSDOS'; + 15= 'WIN3x'; + 16= 'WIN95'; + 17= 'WIN98'; + 18= 'WINNT'; + 19= 'WINCE'; + 20= 'NCR3000'; + 21= 'NetWare'; + 22= 'OSF'; + 23= 'DC/OS'; + 24= 'Reliant UNIX'; + 25= 'SCO UnixWare'; + 26= 'SCO OpenServer'; + 27= 'Sequent'; + 28= 'IRIX'; + 29= 'Solaris'; + 30= 'SunOS'; + 31= 'U6000'; + 32= 'ASERIES'; + 33= 'TandemNSK'; + 34= 'TandemNT'; + 35= 'BS2000'; + 36= 'LINUX'; + 37= 'Lynx'; + 38= 'XENIX'; + 39= 'VM/ESA'; + 40= 'Interactive UNIX'; + 41= 'BSDUNIX'; + 42= 'FreeBSD'; + 43= 'NetBSD'; + 44= 'GNU Hurd'; + 45= 'OS9'; + 46= 'MACH Kernel'; + 47= 'Inferno'; + 48= 'QNX'; + 49= 'EPOC'; + 50= 'IxWorks'; + 51= 'VxWorks'; + 52= 'MiNT'; + 53= 'BeOS'; + 54= 'HP MPE'; + 55= 'NextStep'; + 56= 'PalmPilot'; + 57= 'Rhapsody'; + 58= 'Windows 2000'; + 59= 'Dedicated'; + 60= 'OS/390'; + 61= 'VSE'; + 62= 'TPF'; +} + [hashtable]$ProviderEnums = @{ - #/lib/provider/bios.psm1 + #/lib/provider/bios BiosCharacteristics = $BiosCharacteristics; - #/lib/provider/disks.psm1 + #/lib/provider/disks DiskCapabilities = $DiskCapabilities; - #/lib/provider/cpu.psm1 + #/lib/provider/cpu CPUArchitecture = $CPUArchitecture; CPUProcessorType = $CPUProcessorType; CPUStatusInfo = $CPUStatusInfo; @@ -392,11 +484,15 @@ CPUConfigManagerErrorCode = $CPUConfigManagerErrorCode; CPUAvailability = $CPUAvailability; CPUPowerManagementCapabilities = $CPUPowerManagementCapabilities; - #/lib/provider/memory.psm1 + #/lib/provider/memory MemoryFormFactor = $MemoryFormFactor; MemoryInterleavePosition = $MemoryInterleavePosition; MemoryMemoryType = $MemoryMemoryType; MemoryTypeDetail = $MemoryTypeDetail; + #/lib/provider/windows + WindowsOSProductSuite = $WindowsOSProductSuite; + WindowsProductType = $WindowsProductType; + WindowsOSType = $WindowsOSType; } Export-ModuleMember -Variable @('ProviderEnums'); \ No newline at end of file diff --git a/lib/provider/memory/Icinga_ProviderMemory.psm1 b/lib/provider/memory/Icinga_ProviderMemory.psm1 index 2631ae6..cbe0a9c 100644 --- a/lib/provider/memory/Icinga_ProviderMemory.psm1 +++ b/lib/provider/memory/Icinga_ProviderMemory.psm1 @@ -1,4 +1,4 @@ -Import-Module $IncludeDir\provider\enums; +Import-Module $IncludeDir\provider\enums\Icinga_ProviderEnums; function Get-IcingaMemory () { <# Collects the most important Memory informations, diff --git a/lib/provider/windows/Icinga_ProviderWindows.psm1 b/lib/provider/windows/Icinga_ProviderWindows.psm1 index 0d40c7d..068ce6d 100644 --- a/lib/provider/windows/Icinga_ProviderWindows.psm1 +++ b/lib/provider/windows/Icinga_ProviderWindows.psm1 @@ -1,11 +1,42 @@ -function Show-IcingaWindowsData() +Import-Module $IncludeDir\provider\enums\Icinga_ProviderEnums; + +function Get-IcingaWindows() { $WindowsInformations = Get-CimInstance Win32_OperatingSystem; $windows_datails = @{}; - foreach($cpu_core in $WindowsInformations.CimInstanceProperties) { - $windows_datails.Add($cpu_core.Name, $cpu_core.Value); - } + $windows_datails.Add( + 'windows', @{ + 'metadata' = @{ + 'Version' = $WindowsInformations.Version; + 'CurrentTimeZone' = $WindowsInformations.CurrentTimeZone; + 'InstallDate' = $WindowsInformations.InstallDate; + 'SystemDevice' = $WindowsInformations.SystemDevice; + 'SystemDirectory' = $WindowsInformations.SystemDirectory; + 'BuildType' = $WindowsInformations.BuildType; + 'BuildNumber' = $WindowsInformations.BuildNumber; + 'OSArchitecture' = $WindowsInformations.OSArchitecture; + 'NumberOfUsers' = $WindowsInformations.NumberOfUsers; + 'OSType' = @{ + 'raw' = $WindowsInformations.OSType; + 'value' = $ProviderEnums.WindowsOSType[[int]$WindowsInformations.OSType]; + }; + 'OSProductSuite' = @{ + 'raw' = $WindowsInformations.OSProductSuite; + 'value' = $ProviderEnums.WindowsOSProductSuite[[int]$WindowsInformations.OSProductSuite]; + }; + 'ProductType' = @{ + 'raw' = $WindowsInformations.ProductType; + 'value' = $ProviderEnums.WindowsProductType[[int]$WindowsInformations.ProductType]; + }; + }; + 'language' = @{ + 'CountryCode' = $WindowsInformations.CountryCode; + 'OSLanguage' = $WindowsInformations.OSLanguage; + 'Locale' = $WindowsInformations.Locale; + } + } + ); return $windows_datails; } \ No newline at end of file diff --git a/lib/provider/windows/Show-IcingaWindowsData.psm1 b/lib/provider/windows/Show-IcingaWindowsData.psm1 new file mode 100644 index 0000000..0d40c7d --- /dev/null +++ b/lib/provider/windows/Show-IcingaWindowsData.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 From 1a5dbb392a7e51013a4d967c460fd827fb0b1834 Mon Sep 17 00:00:00 2001 From: Crited Date: Mon, 22 Jul 2019 15:53:07 +0200 Subject: [PATCH 09/10] Binary-Addition in relevant files for enums --- lib/provider/memory/Icinga_ProviderMemory.psm1 | 10 +++++++++- lib/provider/windows/Icinga_ProviderWindows.psm1 | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/provider/memory/Icinga_ProviderMemory.psm1 b/lib/provider/memory/Icinga_ProviderMemory.psm1 index cbe0a9c..89e544d 100644 --- a/lib/provider/memory/Icinga_ProviderMemory.psm1 +++ b/lib/provider/memory/Icinga_ProviderMemory.psm1 @@ -8,6 +8,14 @@ function Get-IcingaMemory () [hashtable]$MEMData = @{}; foreach($memory in $MEMInformation) { + + $TypeDetail = @(); + $ProviderEnums.MemoryTypeDetail.Keys | Where-Object { + $_ -band $memory.TypeDetail + } | ForEach-Object { + $TypeDetail += $ProviderEnums.MemoryTypeDetail.Get_Item($_); + }; + $MEMData.Add( $memory.tag.trim("Physical Memory"), @{ 'metadata' = @{ @@ -46,7 +54,7 @@ function Get-IcingaMemory () }; 'TypeDetail' = @{ 'raw' = $memory.TypeDetail; - 'value' = $ProviderEnums.MemoryTypeDetail[[int]$memory.TypeDetail]; + 'value' = $TypeDetail; }; }; 'specs' = @{ diff --git a/lib/provider/windows/Icinga_ProviderWindows.psm1 b/lib/provider/windows/Icinga_ProviderWindows.psm1 index 068ce6d..57b1a88 100644 --- a/lib/provider/windows/Icinga_ProviderWindows.psm1 +++ b/lib/provider/windows/Icinga_ProviderWindows.psm1 @@ -1,9 +1,17 @@ Import-Module $IncludeDir\provider\enums\Icinga_ProviderEnums; + function Get-IcingaWindows() { $WindowsInformations = Get-CimInstance Win32_OperatingSystem; + $OSProductSuite = @(); + $ProviderEnums.WindowsOSProductSuite.Keys | Where-Object { + $_ -band $WindowsInformations.OSProductSuite + } | ForEach-Object { + $OSProductSuite += $ProviderEnums.WindowsOSProductSuite.Get_Item($_); + }; + $windows_datails = @{}; $windows_datails.Add( 'windows', @{ @@ -23,7 +31,7 @@ function Get-IcingaWindows() }; 'OSProductSuite' = @{ 'raw' = $WindowsInformations.OSProductSuite; - 'value' = $ProviderEnums.WindowsOSProductSuite[[int]$WindowsInformations.OSProductSuite]; + 'value' = $OSProductSuite; }; 'ProductType' = @{ 'raw' = $WindowsInformations.ProductType; From 34c001c761ecdc06e3ea34e150966e88dba653fe Mon Sep 17 00:00:00 2001 From: Crited Date: Mon, 22 Jul 2019 15:59:47 +0200 Subject: [PATCH 10/10] Changed Import-Module to fit with Import-ModuleLib Concept --- icinga-module-windows.psm1 | 2 -- lib/provider/bios/Icinga_ProviderBios.psm1 | 2 +- lib/provider/cpu/Icinga_ProviderCpu.psm1 | 2 +- lib/provider/disks/Icinga_ProviderDisks.psm1 | 2 +- lib/provider/memory/Icinga_ProviderMemory.psm1 | 2 +- lib/provider/process/Icinga_ProviderProcess.psm1 | 3 ++- lib/provider/windows/Icinga_ProviderWindows.psm1 | 3 +-- 7 files changed, 7 insertions(+), 9 deletions(-) diff --git a/icinga-module-windows.psm1 b/icinga-module-windows.psm1 index 70c3552..3d84e5e 100644 --- a/icinga-module-windows.psm1 +++ b/icinga-module-windows.psm1 @@ -9,8 +9,6 @@ #> -$global:IncludeDir = "$PSScriptRoot\lib"; - function Install-Icinga() { [string]$command = Get-Icinga-Command('setup'); diff --git a/lib/provider/bios/Icinga_ProviderBios.psm1 b/lib/provider/bios/Icinga_ProviderBios.psm1 index 41eeb87..76e6a73 100644 --- a/lib/provider/bios/Icinga_ProviderBios.psm1 +++ b/lib/provider/bios/Icinga_ProviderBios.psm1 @@ -1,4 +1,4 @@ -Import-Module $IncludeDir\provider\enums; +Import-IcingaLib provider\enums; function Get-IcingaBios() { <# Collects the most important BIOS informations, diff --git a/lib/provider/cpu/Icinga_ProviderCpu.psm1 b/lib/provider/cpu/Icinga_ProviderCpu.psm1 index 9324ba8..6dac6c8 100644 --- a/lib/provider/cpu/Icinga_ProviderCpu.psm1 +++ b/lib/provider/cpu/Icinga_ProviderCpu.psm1 @@ -1,4 +1,4 @@ -Import-Module $IncludeDir\provider\enums; +Import-IcingaLib provider\enums; function Get-IcingaCPUs() { <# Collects the most important CPU informations, diff --git a/lib/provider/disks/Icinga_ProviderDisks.psm1 b/lib/provider/disks/Icinga_ProviderDisks.psm1 index 74dab9e..b03a8b6 100644 --- a/lib/provider/disks/Icinga_ProviderDisks.psm1 +++ b/lib/provider/disks/Icinga_ProviderDisks.psm1 @@ -1,4 +1,4 @@ -Import-Module $IncludeDir\provider\enums; +Import-IcingaLib provider\enums; function Get-IcingaDiskInformation() { diff --git a/lib/provider/memory/Icinga_ProviderMemory.psm1 b/lib/provider/memory/Icinga_ProviderMemory.psm1 index 89e544d..f9abcd0 100644 --- a/lib/provider/memory/Icinga_ProviderMemory.psm1 +++ b/lib/provider/memory/Icinga_ProviderMemory.psm1 @@ -1,4 +1,4 @@ -Import-Module $IncludeDir\provider\enums\Icinga_ProviderEnums; +Import-IcingaLib provider\enums; function Get-IcingaMemory () { <# Collects the most important Memory informations, diff --git a/lib/provider/process/Icinga_ProviderProcess.psm1 b/lib/provider/process/Icinga_ProviderProcess.psm1 index 729138b..c86c6ee 100644 --- a/lib/provider/process/Icinga_ProviderProcess.psm1 +++ b/lib/provider/process/Icinga_ProviderProcess.psm1 @@ -1,4 +1,5 @@ -Import-Module $IncludeDir\provider\cpu; +Import-IcingaLib provider\enums; +Import-IcingaLib provider\cpu; function Add-IcingaProcessPerfData() { diff --git a/lib/provider/windows/Icinga_ProviderWindows.psm1 b/lib/provider/windows/Icinga_ProviderWindows.psm1 index 57b1a88..d0d5d6d 100644 --- a/lib/provider/windows/Icinga_ProviderWindows.psm1 +++ b/lib/provider/windows/Icinga_ProviderWindows.psm1 @@ -1,5 +1,4 @@ -Import-Module $IncludeDir\provider\enums\Icinga_ProviderEnums; - +Import-IcingaLib provider\enums; function Get-IcingaWindows() {