windows_exporter/tools/collector-generator/New-Collector.ps1

32 lines
1.0 KiB
PowerShell
Raw Normal View History

2016-09-24 09:49:09 +00:00
Param(
[Parameter(Mandatory=$true)]
$Class,
[Parameter(Mandatory=$false)]
$CollectorName = ($Class -replace 'Win32_PerfRawData_Perf',''),
[Parameter(Mandatory=$false)]
$ComputerName = "localhost",
[Parameter(Mandatory=$false)]
$Credential
2016-09-24 09:49:09 +00:00
)
$ErrorActionPreference = "Stop"
if($Credential -ne $null) {
$wmiObject = Get-WMIObject -ComputerName $ComputerName -Credential $Credential -Class $Class
}
else {
$wmiObject = Get-WMIObject -ComputerName $ComputerName -Class $Class
}
$members = @($wmiObject `
2016-09-24 09:49:09 +00:00
| Get-Member -MemberType Properties `
| Where-Object { $_.Definition -Match '^u?int' -and $_.Name -NotMatch '_' } `
| Select-Object Name, @{Name="Type";Expression={$_.Definition.Split(" ")[0]}}
$input = @{
"Class"=$Class;
"CollectorName"=$CollectorName;
"Members"=$members
} | ConvertTo-Json)
2016-09-24 09:49:09 +00:00
$outFileName = "..\..\collector\$CollectorName.go".ToLower()
$input | .\collector-generator.exe | Out-File -NoClobber -Encoding UTF8 $outFileName
go fmt $outFileName