1 Reply Latest reply on Oct 31, 2017 9:17 AM by Peoplesbank

    PowerShell Invoke-WebRequest  not returning data from CAI WebControl temperature readings

    Peoplesbank

      I really have no experience setting up SAM monItors or powershell scripts but I have managed to create a powershell monitor component and application to store the temperature readings from a CAI WebControl 8 device.  This device does not support SNMP but can be polled with PS ver3 using

      [xml]$xml = 'Invoke-WebRequest -uri ${IP}/getall.cgi'.

       

      I can get the script to connect and run correctly from the powershell screen on the Orion SAM server but cannot get any data to populate the xml variable from the Component.  I have tested the script by forcing data into the variables and see the correct Statistic and Messages in the application.    Eventually we will have 60+ of these devices to monitor.

       

      It appears that the INVOKE-WebRequest is not getting any data back no matter what type of variable is used?  Is there any other way to get data from an HTML  page that works in the PowerShell Monitor?

       

      I have attached my script.

      -------------------------------------------------------------------------------------------------------------------------------

      #NO Arguments  - CAI WebControl 8 device can support  8 DS18b20 one-wire temperature sensors

       

      # get current readings from WebControl appliance  -login has been disabled for testing.

      [xml]$xml = Invoke-WebRequest -uri ${IP}/getall.cgi

       

      for($sensor=1; $sensor -le 8; $sensor++)

      {

         $romcode_element = "boundromcode$sensor"

         $stat_element = "tstat$sensor"

         $temp_element = "ts$sensor"

       

         #get requested sensor# status  (OK, FAILED, UNKNOWN)

         $status = $xml.response.$stat_element

       

         #get requested sensor# temp and remove F from string then convert to [INT]

         $temperature =  $xml.response.$temp_element

         $temperature = $temperature.replace("F","")

         $temperature = [int]$temperature

       

         #get requested sensor# DS18B20 temp sensor ROM number

         $romcode =  $xml.response.$romcode_element

       

         # Setup message:

         $msg = "Sensor # $sensor  serial #: $romcode  - Status is:  $status"

       

         if ($sensor -eq "1")

            {$TS1 = $temperature

            $MSG1 = $msg}

         elseif ($sensor -eq "2")

            {$TS2 = $temperature

            $MSG2 = $msg}

         elseif ($sensor -eq "3")

            {$TS3 = $temperature

            $MSG3 = $msg}

        elseif ($sensor-eq "4")

            {$TS4 = $temperature

            $MSG4 = $msg}

        elseif ($sensor-eq "5")

            {$TS5 = $temperature

            $MSG5 = $msg}

        elseif ($sensor-eq "6")

            {$TS6 = $temperature

            $MSG6 = $msg}

        elseif ($sensor-eq "7")

            {$TS7 = $temperature

            $MSG7 = $msg}

        elseif ($sensor-eq "8")

            {$TS8 = $temperature

            $MSG8 = $msg}

      }

       

      write-host "Statistic.1:  $TS1"

      write-host "Message.1: $MSG1"

      write-host "Statistic.2:  $TS2"

      write-host "Message.2: $MSG2"

      write-host "Statistic.3:  $TS3"

      write-host "Message.3: $MSG3"

      write-host "Statistic.4:  $TS4"

      write-host "Message.4: $MSG4"

      write-host "Statistic.5:  $TS5"

      write-host "Message.5: $MSG5"

      write-host "Statistic.6:  $TS6"

      write-host "Message.6: $MSG6"

      write-host "Statistic.7:  $TS7"

      write-host "Message.7: $MSG7"

      write-host "Statistic.8:  $TS8"

      write-host "Message.8: $MSG8"

      exit 0

       

       

       

      NPM 12.0.1 / SAM 6.3.0

        • Re: PowerShell Invoke-WebRequest  not returning data from CAI WebControl temperature readings
          Peoplesbank

          I FINALLY found the problem(s) and have the script running!

           

          For anyone else having problems with the Power Shell Monitor - here are my findings.

           

          After a long search through manuals, THWACK, and Google, I finally found that the Debug Logging files are in C:\ProgramData\SolarWinds\Logs\APM\ApplicationLogs\ AppID###  (you will need to find the current folder being used).

           

          The logs showed the error: "Invoke-WebRequest: The response content cannot be parsed because the Internet Explorer engine is not available, or Internet Explorer's first-launch configuration is not complete.  Specify the UseBasicParsing parameter and try again."

           

          I found a thread in THWACK that shows the steps needed to modify the Orion server's registry to disable the IE First-Launch entry:

          Invoke-WebRequest Powershell HTML Parsing

           

          Then I had to add -UseBasicParsing to the Invoke-WebRequest command.  Here is the correct command:

          [xml]$xml = Invoke-WebRequest -uri 'http://${IP}/getall.cgi' -UseBasicParsing

           

          It would have been nice if the log location was in the SAM admin guides where it discusses the CREATING TEMPLATES -ADVANCED -DEBUG LOGGING check box instead of the "Contact Support to use this feature" comment!