This is an old revision of the document!


How can I measure the availability of my routers?

Of course you can setup a Network Monitoring Tool (NMS) such as Zabbix. An easier and faster way is to run the following PowerShell script:

$hosts += “IP or DynDNS Name of my Routers” $fname = “results.csv” while($true) {

  $date = Get-Date -format G
  $newtime = Get-Date -format t
  # if ( $newtime -gt $time ) {
  if ( $true ) {
      $time = $newtime
      if ($hosts -isnot [system.array]) {
          $hosts = Get-Content $hosts
      }
      $hosts | Foreach-Object { 
          $pinghost = $_
          $psObject = $null
          $psObject = New-Object psobject
          Add-Member -InputObject $psobject -MemberType NoteProperty -Name "Date" -Value $date
          Add-Member -InputObject $psobject -MemberType NoteProperty -Name "Host" -Value $pinghost
          $status = Test-Connection –count 1 $pinghost  -ErrorAction SilentlyContinue
          if ($status.statuscode -eq 0) {
              $psobject | Add-Member -MemberType NoteProperty -Name "IP" -Value $status.IPV4Address
              $psobject | Add-Member -MemberType NoteProperty -Name "ResponseTime" -Value $status.ResponseTime
              $psobject | Add-Member -MemberType NoteProperty -Name "State" -Value "up"
              $psObject | Export-Csv $fname -Encoding UTF8 -Delimiter ";" -Append -NoTypeInformation
              #$outText = "$($psobject.Date); $($psobject.Host); $($psobject.IP); $($psobject.ResponseTime); $($psobject.State)"
              #$outText | Out-File -Encoding UTF8 -FilePath $fname -Append
              #$outText >> $fname 
              Write-Host  $psObject 
          } else {
              $status2 = Test-Connection –count 1 $pinghost -ErrorAction SilentlyContinue
              if ($status2.statuscode -eq 0) {
                  $psobject | Add-Member -MemberType NoteProperty -Name "IP" -Value $status2.IPV4Address
                  $psobject | Add-Member -MemberType NoteProperty -Name "ResponseTime" -Value $status2.ResponseTime
                  $psobject | Add-Member -MemberType NoteProperty -Name "State" -Value "up"
                  $psObject | Export-Csv $fname -Encoding UTF8 -Delimiter ";" -Append -NoTypeInformation
                  Write-Host $psobject  -ForegroundColor black -BackgroundColor green
              } else {
                  $psobject | Add-Member -MemberType NoteProperty -Name "IP" -Value ="n/a"
                  $psobject | Add-Member -MemberType NoteProperty -Name "ResponseTime" -Value "-100"
                  $psobject | Add-Member -MemberType NoteProperty -Name "State" -Value "down"
                  $psObject | Export-Csv $fname -Encoding UTF8 -Delimiter ";" -Append -NoTypeInformation
                  Write-Host $psobject -BackgroundColor Red
              }
          }
      }
  }
  Write-Host "wait another 5 seconds for for next check ..."
  Start-Sleep 5

}