all scripts

This commit is contained in:
Alexpolo1
2023-03-09 09:06:25 +01:00
parent 49b677d254
commit bf7c3012b7
115 changed files with 68517 additions and 0 deletions

View File

@@ -0,0 +1,69 @@
pushd C:\Users\a.warme\Documents\ # my temp dir
# read in file as an array to compare to in nagios config
$nagios = Get-Content -Path C:\ew-nagios\prod\etc\nagios\local\hostgroup-accesspoints.cfg -raw
# start scanning the file for matches to file entries from export of prod nps clients
$nps = Get-Content -Path C:\Users\a.warme\Documents\nps_cleanup\rej-p-rad002_nps.txt
#build custom object with ip, name , and found status
$result = foreach($line in $nps) {
if($line -match 'Name *= (.*)') {
$obj = [pscustomobject]@{
IP = ''
Name = $Matches[1]
Found = ''
}
Write-Verbose -Verbose "'$line' matches Name - $($Matches[1])"
}
#put matches into object
elseif($line -match 'Address *= (.*)') {
$obj.IP = $Matches[1]
$obj.Found = $nagios -match $obj.IP
Write-Output $obj
Write-Verbose -Verbose "'$line' matches Address - $($Matches[1])"
}
else {
Write-Verbose -Verbose "'$line' has no match"
}
}
#for grid view use
#$result | Out-GridView
#bulding a template for nagios hostgroup
$template = @'
define service {{
hostgroup_name AccessPoints
service_description {0}-{1}
use thales-service
check_command check_ap!{2}
check_interval 15
max_check_attempts 3
retry_interval 1
servicegroups spoc-monitoring,system-monitoring
}}
'@
#matching with not found adress and ip
$notFound = $result | Where found -eq $false
#insert adress and ip into template
$output = foreach($obj in $notFound) {
$template -f $obj.Name, $obj.IP, $obj.IP
}
#copy clipboard into hostgroup-accesspoints.cfg , remember to check for # or wierd spaces
$output | Set-Clipboard