Announcement

Collapse
No announcement yet.

APC UPS script - exception error when converting string

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    APC UPS script - exception error when converting string

    Jon,

    Since I have been running the APC UPS monitoring script, I get an error in the HS log every day or two. I have the APC UPS software logging data every minute and the script is running every minute. I'm guessing the APC software might be updating the file with data at the exact moment the script reads it which causes the script to get a partial line of data. What do you think is causing this?


    Scripting runtime error: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidCastException: Conversion from string "" to type 'Single' is not valid. ---> System.FormatException: Input string was not in a correct format. at Microsoft.VisualBasic.CompilerServices.Conversions.ParseDoub le(String Value, NumberFormatInfo NumberFormat) at Microsoft.VisualBasic.CompilerServices.Conversions.ToSingle( String Value, NumberFormatInfo NumberFormat) --- End of inner exception stack trace --- at Microsoft.VisualBasic.CompilerServices.Conversions.ToSingle( String Value, NumberFormatInfo NumberFormat) at Microsoft.VisualBasic.CompilerServices.Conversions.ToSingle( Object Value, NumberFormatInfo NumberFormat) at Microsoft.VisualBasic.CompilerServices.Conversions.ToSingle( Object Value) at scriptcode4.scriptcode4.Trigger(Object DeviceText, Object IniName, Object SensorData, Object Unit) at scriptcode4.scriptcode4.Main(Object parm) --- End of inner exception stack trace --- at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) at Scheduler.VsaScriptHost.Invoke(String ModuleName, String MethodName, Object[] Arguments)

    #2
    It could well be or that it did not receive any data at all.


    Above the line:

    Dim MyLeft As String

    Add:

    If Len(data)=0 then
    hs.writelog ("UPS monitor","No data obtained. Script terminated")
    exit sub
    end if

    See if that stops the error.
    Jon

    Comment


      #3
      I put this code in place in each script. Time will tell.

      Thanks.

      Comment


        #4
        I got another error. Since the script didn't terminate, the code that was added must not be catching the case. I'm not sure how to troubleshoot this further.

        Comment


          #5
          That's not a problem. I'll put proper error trapping in soon. It's just one of those scripts I don't use hence they get neglected!
          Jon

          Comment


            #6
            That would be great. Although the errors happen very infrequently (1 in 5000 script executions), I'd like to understand why so I can learn something.

            Comment


              #7
              Check your email...I've sent you a new version to try!
              Jon

              Comment


                #8
                I have the new version running. I will let you know when it reports.

                Thanks.

                Comment


                  #9
                  It's been running for several days now and I haven't received a single error or a report in the log that an error was trapped. This is very strange since I was getting an error about once/day. I double-checked and I do have the error logging enabled.

                  Good enough!

                  Comment


                    #10
                    In addition to the trapping, there was a bit of code changing which I thought could cause the error. Looks like it worked!

                    I'll put this version out for general release soon.
                    Jon

                    Comment


                      #11
                      I knew posting a message would make something happen. About 30 minutes ago, the HS log showed this for one of the UPS's (and I know which one because I customized the scripts for each unit by specifying the name):

                      No data obtained. Script terminated

                      So, for some reason the data length was zero.

                      Comment


                        #12
                        If one program is writing at exactly the same time as another is reading, it can happen.

                        Once your happy, just turn the error logging off and forget
                        Jon

                        Comment


                          #13
                          Yes, the file system was never intended to be used this way, of course, but it's certainly good enough for me to miss a report once/day when they are being generated once/minute. A database would be more appropriate where the transactions could be policed. Someday I may look into using SNMP messages from the APC software as that would be ideal in terms of cpu/network/disk utilization.

                          The null data input is definitely being trapped, so everything looks good to me.

                          Thanks again.

                          Comment


                            #14
                            Some other errors were trapped this morning. It seems like the main data file input might be the only data that could be null and not these. Any thoughts?

                            12/10/2008 6:10:17 AM ~!~UPS~!~Error in subroutine trigger at block C (Conversion from string "" to type 'Single' is not valid.)
                            12/10/2008 6:10:17 AM ~!~UPS~!~Error in subroutine trigger at block D (Conversion from string "" to type 'Single' is not valid.)
                            12/10/2008 6:10:17 AM ~!~UPS~!~Error in subroutine trigger at block E (Conversion from string "" to type 'Single' is not valid.)
                            12/10/2008 6:10:17 AM ~!~UPS~!~Error in subroutine trigger at block C (Conversion from string "" to type 'Single' is not valid.)
                            12/10/2008 6:10:17 AM ~!~UPS~!~Error in subroutine trigger at block D (Conversion from string "" to type 'Single' is not valid.)
                            12/10/2008 6:10:17 AM ~!~UPS~!~Error in subroutine trigger at block E (Conversion from string "" to type 'Single' is not valid.)
                            12/10/2008 6:10:18 AM ~!~UPS~!~Error in subroutine trigger at block C (Conversion from string "" to type 'Single' is not valid.)
                            12/10/2008 6:10:18 AM ~!~UPS~!~Error in subroutine trigger at block D (Conversion from string "" to type 'Single' is not valid.)
                            12/10/2008 6:10:18 AM ~!~UPS~!~Error in subroutine trigger at block E (Conversion from string "" to type 'Single' is not valid.)
                            12/10/2008 6:10:18 AM ~!~UPS~!~Error in subroutine trigger at block C (Conversion from string "" to type 'Single' is not valid.)
                            12/10/2008 6:10:18 AM ~!~UPS~!~Error in subroutine trigger at block D (Conversion from string "" to type 'Single' is not valid.)
                            12/10/2008 6:10:18 AM ~!~UPS~!~Error in subroutine trigger at block E (Conversion from string "" to type 'Single' is not valid.)
                            12/10/2008 6:10:18 AM ~!~UPS~!~Error in subroutine trigger at block C (Conversion from string "" to type 'Single' is not valid.)
                            12/10/2008 6:10:18 AM ~!~UPS~!~Error in subroutine trigger at block D (Conversion from string "" to type 'Single' is not valid.)
                            12/10/2008 6:10:18 AM ~!~UPS~!~Error in subroutine trigger at block E (Conversion from string "" to type 'Single' is not valid.)
                            12/10/2008 6:10:18 AM ~!~UPS~!~Error in subroutine main at block K (Conversion from string "" to type 'Double' is not valid.)

                            Comment


                              #15
                              I would say it is another clash but this time, some of the data was read.

                              Please add this code to the Sub Trigger routine:

                              From:

                              Try

                              LoggingEnable=hs.GetINISetting("Settings","LoggingEnable","" ,IniName)
                              INIHeader = Replace(DeviceText," ","_",1,-1,1)

                              To:

                              Try

                              If Len(SensorData)=0 then
                              If ErrorLogging=1 then hs.writelog("Jon00_UPS-APC","No sensor data")
                              exit sub
                              end if
                              LoggingEnable=hs.GetINISetting("Settings","LoggingEnable","" ,IniName)
                              INIHeader = Replace(DeviceText," ","_",1,-1,1)

                              See if that catches anything more.
                              Jon

                              Comment

                              Working...
                              X