37 lines
1.7 KiB
PowerShell
37 lines
1.7 KiB
PowerShell
Set-Location 'C:\Users\m.nielsen\desktop\Scripts\thales'
|
|
|
|
$content = Get-Content -Raw -Path commands.cfg
|
|
$matches = [regex]::Matches($content, 'define command *{.*?command_name *(?<command_name>.*?)\n *command_line *(?<command_line>.*?)\n}', [System.Text.RegularExpressions.RegexOptions]::Singleline)
|
|
$commands = foreach($m in $matches) {
|
|
Write-Output ([pscustomobject]@{
|
|
CommandName = $m.Groups['command_name'].Value
|
|
CommandLine = $m.Groups['command_line'].Value
|
|
})
|
|
}
|
|
|
|
|
|
$services = foreach($file in (Get-Item .\hostgroup_*.cfg, .\serviceTemplates.cfg)) {
|
|
$content = Get-Content -Raw $file
|
|
|
|
$matches = [regex]::Matches($content, '{(?<content>.*?)}', [System.Text.RegularExpressions.RegexOptions]::Singleline)
|
|
|
|
foreach($m in $matches) {
|
|
$hostgroup = [regex]::Match($m.Groups['content'].Value, 'hostgroup_name *(.*)').Groups[1].Value
|
|
$hostname = [regex]::Match($m.Groups['content'].Value, 'host_name *(.*)').Groups[1].Value
|
|
$servicedescription = [regex]::Match($m.Groups['content'].Value, 'service_description *(.*)').Groups[1].Value
|
|
$servicename = [regex]::Match($m.Groups['content'].Value, 'service_name *(.*)').Groups[1].Value
|
|
$checkcommand = [regex]::Match($m.Groups['content'].Value, 'check_command *(.*)').Groups[1].Value
|
|
$use = [regex]::Match($m.Groups['content'].Value, 'use *(.*)').Groups[1].Value
|
|
|
|
Write-Output ([pscustomobject]@{
|
|
Hostgroup = $hostgroup
|
|
Hostname = $hostname
|
|
CheckCommand = $checkcommand
|
|
Use = $use
|
|
ServiceName = $servicename
|
|
ServiceDescription = $servicedescription
|
|
File = $file.Name
|
|
Content = $m.Groups['content'].Value
|
|
})
|
|
}
|
|
} |