Hi,
so I'm trying to hack together some rudimentary monitoring, I have the below script:
$wd = 'c:\CMX\'
$files = gci $wd
$pwd = pwd
$alerts = "alerts.csv"
$tmp = 'tmp.txt'
cd $wd
foreach ($l in $files){
$ip = $l.BaseName | %{ $_.split('-')[1]; }
$count = get-content $l | %{ $_.split(',')[0]; } | %{ $_.split(':')[1]; }
(Write-Output $ip.Trim() $count.Trim())-join "," >> $alerts
}
# Alerts
$alert = Get-Content $alerts
$chost = @()
$calarm = @()
foreach ($a in $alert){
if($a -notmatch ".*,[0].*"){
$chost+= $a.Split(',')[0];
}
if($a -notmatch ".*,[0].*"){
$calarm+= $a.Split(',')[1];
}
}
write-host "Message.CMXAlertCount:" $chost[0]
write-host "Statistic.CMXAlertCount:" $calarm[0]
rm $alerts
exit 0;
which when run in powershell returns:
array index 0:
Message.CMXAlertCount: 172.16.4.10
Statistic.CMXAlertCount: 1
array index 1:
Message.CMXAlertCount: 172.26.4.10
Statistic.CMXAlertCount: 2
but the above is manual, is there a way to loop it? so dynamically say for each index in the array perform the write host?
if there is, how do i have solarwinds take that output as i believe it will error.
I am querying multiple systems and dumping that data into one file that contains the host ip and the number of active alerts on that host, all i want to be able to do is monitor this file and when an alert value increases trigger something, be it an email or syslog whatever.
this is my first time using SAM so am probably going about it the wrong way, i should add for context the systems are remote and currently solarwinds does not have direct access and is unlikely too.
thanks in advance.