• Recent
    • Tags
    • Popular
    • Register
    • Login

    Please Note This forum exists for community support for the Mango product family and the Radix IoT Platform. Although Radix IoT employees participate in this forum from time to time, there is no guarantee of a response to anything posted here, nor can Radix IoT, LLC guarantee the accuracy of any information expressed or conveyed. Specific project questions from customers with active support contracts are asked to send requests to support@radixiot.com.

    Radix IoT Website Mango 3 Documentation Website Mango 4 Documentation Website Mango 5 Documentation Website

    Process Event handler to fire external script

    User help
    3
    56
    10.4k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • phildunlapP
      phildunlap
      last edited by

      Or, if the source point is binary, use a state detector on true and like Fox said, no inactive action.

      1 Reply Last reply Reply Quote 0
      • K
        khuang @MattFox
        last edited by khuang

        @mattfox said in Process Event handler to fire external script:

        if ( point.last(1,0)[0].value == 0 && point.value == 1 )
        {
        return true; //fire handler
        }

        The logic that I am after is that it fires my script but I do not want the scripts to continuously fire.
        Right now there are two problems:

        1. the set point handler is triggering all the time (the reason why I believe it is triggering all the time is because my set point cannot be set back to 0) and setting my ssh data point to true all the time. It should execute once and be done. Right now the data point is stuck at 1, and I am unable to change it back to 0.
          0_1548955502126_a1d055e5-28bb-4245-9505-450794c2c4d2-image.png
        2. my script which is in the set command of the ssh data point still is not executing, which is the purpose behind me pursuing ssh datasources and data points

        EDIT: I recreated the SSH datapoint, and set point handler and I got the set command to fire but at a 6 second delay. It also looks like the entire MangoES box is lagging at the same rate.

        EDIT2: After restarting the MangoES box and deactivating several other data sources that have various polling and triggers associated with it, the CPU reduced to 360% (8 cores). Before the CPU was being hit too hard so the script was not running correctly.

        1 Reply Last reply Reply Quote 0
        • MattFoxM
          MattFox
          last edited by MattFox

          For your virtual datapoint, if it's set to logging all it'll continuously update/trigger the event.
          Set logging to update on point value change only as you only need it to work when it changes between 1 and 0, not 1 and 1.

          Do not follow where the path may lead; go instead where there is no path.
          And leave a trail - Muriel Strode

          1 Reply Last reply Reply Quote 0
          • phildunlapP
            phildunlap
            last edited by

            It would depend on whatever event detector has been placed on the point.

            MattFoxM 1 Reply Last reply Reply Quote 0
            • MattFoxM
              MattFox @phildunlap
              last edited by

              @phildunlap Also true...

              Do not follow where the path may lead; go instead where there is no path.
              And leave a trail - Muriel Strode

              1 Reply Last reply Reply Quote 0
              • K
                khuang
                last edited by

                Currently for the event detector I have it as "when the state is one". So I guess "when the state is one" means 0 to 1 and 1 to 1?

                What if I created another event detector for "when the state is zero" and kill the process that way?

                1 Reply Last reply Reply Quote 0
                • MattFoxM
                  MattFox
                  last edited by

                  Let's see a screenshot of your datapoint settings.
                  From what I gather, you have an SSH source which runs a python script which then sets the value of the binary datapoint. If that point is set to one, fire an event handler.
                  Does that sound right?

                  Do not follow where the path may lead; go instead where there is no path.
                  And leave a trail - Muriel Strode

                  1 Reply Last reply Reply Quote 0
                  • K
                    khuang
                    last edited by

                    Yes, that is correct.

                    Here is a screenshot of my virtual datapoint which serves as the source for firing the event handler:
                    0_1548963338669_dea875b5-146f-44cd-9d00-459443c1d2ff-image.png
                    I manually set the virtual datapoint so it only goes from 0 to 1 or 1 to 0, and not 0 to 0 or 1 to 1.

                    This is my SSH datapoint which gets set by the event handler. I have it get scripted to return true because I don't care what the value of this data point is but just that the set command gets fired:
                    0_1548963444708_eb98a925-17fd-4813-8736-c9d140d27beb-image.png

                    1 Reply Last reply Reply Quote 0
                    • phildunlapP
                      phildunlap
                      last edited by phildunlap

                      Currently for the event detector I have it as "when the state is one". So I guess "when the state is one" means 0 to 1 and 1 to 1?

                      What if I created another event detector for "when the state is zero" and kill the process that way?

                      Can you post the JSON for the event detector / source point? State event detectors will not retrigger the active event handler from repeated samples of the same state, but would retrigger the event if the point or data source were restarted (i.e. saved, Mango restarts, etc)

                      1 Reply Last reply Reply Quote 0
                      • MattFoxM
                        MattFox
                        last edited by

                        Actually yes, the JSON would be better there is still a lot of information missing.

                        Do not follow where the path may lead; go instead where there is no path.
                        And leave a trail - Muriel Strode

                        1 Reply Last reply Reply Quote 0
                        • K
                          khuang
                          last edited by khuang

                          Yes, here is the JSON of the event handler:

                          {
                             "eventHandlers":[
                                {
                                   "xid":"EH_caaac4a3-6ff5-4046-8eaa-0ff5be6a6370",
                                   "alias":"",
                                   "handlerType":"EMAIL",
                                   "eventTypes":[
                                      {
                                         "sourceType":"DATA_SOURCE",
                                         "XID":"DS_2b8b5316-3bd1-4b4e-82d2-c5f00dbd4ba4",
                                         "dataSourceEventType":"SCRIPT_ERROR"
                                      }
                                   ],
                                   "activeRecipients":[
                                      {
                                         "recipientType":"ADDRESS",
                                         "address":"khuang@cityliftparking.com"
                                      }
                                   ],
                                   "sendEscalation":false,
                                   "sendInactive":false,
                                   "includeSystemInformation":true,
                                   "includePointValueCount":10,
                                   "includeLogfile":true,
                                   "customTemplate":"",
                                   "additionalContext":[
                                   ],
                                   "script":"",
                                   "scriptPermissions":{
                                      "scriptDataPointReadPermission":"superadmin, user",
                                      "scriptDataPointSetPermission":"superadmin, user",
                                      "scriptDataSourcePermission":"superadmin, user"
                                   },
                                   "disabled":false
                                },
                                {
                                   "xid":"EH_2d361442-9b2e-40ff-82bd-3f85c42d3480",
                                   "alias":"",
                                   "handlerType":"SET_POINT",
                                   "eventTypes":[
                                      {
                                         "sourceType":"DATA_POINT",
                                         "dataPointXID":"DP_d8a89826-e771-4760-ac46-9064a5e3b3d0",
                                         "detectorXID":"ED_80c9adf7-f1ad-4058-a60a-05a58f53ecf6"
                                      }
                                   ],
                                   "targetPointId":"DP_41011e72-6228-4ae6-a4e3-6fdce7c45ec7",
                                   "activeAction":"SCRIPT_VALUE",
                                   "activeScript":"return true;",
                                   "inactiveAction":"NONE",
                                   "additionalContext":[
                                   ],
                                   "scriptPermissions":{
                                      "scriptDataPointReadPermission":"superadmin",
                                      "scriptDataPointSetPermission":"superadmin",
                                      "scriptDataSourcePermission":"superadmin"
                                   },
                                   "disabled":false
                                }
                             ]
                          }
                          

                          @phildunlap You said that the script could get retriggered if I restarted the data source and data point, which is what I was doing. So maybe that was the cause. I was restarting the source and point because I was unable to set the ssh data point in the watch list.

                          EDIT: I think I see what the problem might have been (with the lagging). When I restart the SSH data source/point, the event handler fires again and launches my script in another session and it does for each time I restart the source/point. And eventually it hoses up my entire system.

                          1 Reply Last reply Reply Quote 0
                          • phildunlapP
                            phildunlap
                            last edited by

                            @phildunlap said in Process Event handler to fire external script:

                            Can you post the JSON for the event detector / source point?

                            But no matter, the restarting of the point or source was likely the cause of resending. So, now the issue is that even using SSH you're experiencing those issues with python modules being undefined? What was that post about the Hello World text and the SSH invoking the script about? Or, is everything working now and it was melting from the multiple runs of the script?

                            K 1 Reply Last reply Reply Quote 0
                            • K
                              khuang @phildunlap
                              last edited by khuang

                              @phildunlap It was the melting from the multiple runs of the script which made it appear that the script was not working. Right now everything is working. The command in the 'set command' of my ssh datapoint is firing when the state changes to true for my source whereas it the same command was giving errors in the process event handler so the lesson learned for me is to use a set point event handler when my script uses relative paths and environmental variables.

                              Only problem now is I need to be careful because each time the source goes to 1, it starts up another run of my script and with 3 of those, my system crashes. Now I just need a way to kill the process when the state changes to false.

                              1 Reply Last reply Reply Quote 0
                              • MattFoxM
                                MattFox
                                last edited by

                                It's going to be related to event detector and point settings. Export the JSON for the point, we cannot see how you've got the event detector configured and point settings configured

                                Do not follow where the path may lead; go instead where there is no path.
                                And leave a trail - Muriel Strode

                                1 Reply Last reply Reply Quote 0
                                • phildunlapP
                                  phildunlap
                                  last edited by

                                  You can add another virtual point into the context for the set point handler, and set a value to it in the script before returning. Then in the script you do something like this,

                                  if( lastSet.time >= CONTEXT.getRuntime() - 15000 ) //15 seconds
                                    return UNCHANGED;
                                  lastSet.set(!lastSet.value); //we care about times, not values, so alternate a binary
                                  return true;
                                  
                                  1 Reply Last reply Reply Quote 0
                                  • K
                                    khuang
                                    last edited by

                                    @MattFox This is the SSH data point:

                                    {
                                            "xid":"DP_41011e72-6228-4ae6-a4e3-6fdce7c45ec7",
                                            "name":"Trigger",
                                            "enabled":true,
                                            "loggingType":"ON_CHANGE",
                                            "intervalLoggingPeriodType":"MINUTES",
                                            "intervalLoggingType":"INSTANT",
                                            "purgeType":"YEARS",
                                            "pointLocator":{
                                               "dataType":"ALPHANUMERIC",
                                               "setCommand":"\/home\/mango\/detect-start.sh",
                                               "queryable":false,
                                               "settable":true
                                            },
                                            "eventDetectors":[
                                            ],
                                            "plotType":"STEP",
                                            "rollup":"NONE",
                                            "unit":"",
                                            "templateXid":"Alphanumeric_Default",
                                            "simplifyType":"NONE",
                                            "chartColour":"red",
                                            "chartRenderer":{
                                               "type":"TABLE",
                                               "limit":10
                                            },
                                            "dataSourceXid":"DS_40cb68b0-350f-4b16-b54b-5bc359cf8241",
                                            "defaultCacheSize":1,
                                            "deviceName":"MangoES",
                                            "discardExtremeValues":false,
                                            "discardHighLimit":1.7976931348623157E308,
                                            "discardLowLimit":-1.7976931348623157E308,
                                            "intervalLoggingPeriod":15,
                                            "intervalLoggingSampleWindowSize":0,
                                            "overrideIntervalLoggingSamples":false,
                                            "preventSetExtremeValues":false,
                                            "purgeOverride":false,
                                            "purgePeriod":1,
                                            "readPermission":"",
                                            "setExtremeHighLimit":1.7976931348623157E308,
                                            "setExtremeLowLimit":-1.7976931348623157E308,
                                            "setPermission":"",
                                            "tags":{
                                            },
                                            "textRenderer":{
                                               "type":"PLAIN",
                                               "useUnitAsSuffix":true,
                                               "unit":"",
                                               "renderedUnit":"",
                                               "suffix":""
                                            },
                                            "tolerance":0.0
                                         },
                                    

                                    And here's the virtual data point that I use to trigger:

                                     {
                                             "xid":"DP_d8a89826-e771-4760-ac46-9064a5e3b3d0",
                                             "name":"doorIsOpen",
                                             "enabled":true,
                                             "loggingType":"ON_CHANGE",
                                             "intervalLoggingPeriodType":"MINUTES",
                                             "intervalLoggingType":"INSTANT",
                                             "purgeType":"YEARS",
                                             "pointLocator":{
                                                "dataType":"BINARY",
                                                "changeType":{
                                                   "type":"NO_CHANGE",
                                                   "startValue":"True"
                                                },
                                                "settable":true
                                             },
                                             "eventDetectors":[
                                                {
                                                   "type":"BINARY_STATE",
                                                   "sourceType":"DATA_POINT",
                                                   "xid":"ED_80c9adf7-f1ad-4058-a60a-05a58f53ecf6",
                                                   "name":"",
                                                   "alarmLevel":"NONE",
                                                   "durationType":"SECONDS",
                                                   "duration":0,
                                                   "state":true
                                                },
                                                {
                                                   "type":"BINARY_STATE",
                                                   "sourceType":"DATA_POINT",
                                                   "xid":"ED_915a14f9-17da-4885-9c22-a53648617c04",
                                                   "name":"",
                                                   "alarmLevel":"NONE",
                                                   "durationType":"SECONDS",
                                                   "duration":0,
                                                   "state":false
                                                }
                                             ],
                                             "plotType":"STEP",
                                             "rollup":"NONE",
                                             "unit":"",
                                             "templateXid":"Binary_Default",
                                             "simplifyType":"NONE",
                                             "chartColour":"blue",
                                             "chartRenderer":{
                                                "type":"TABLE",
                                                "limit":10
                                             },
                                             "dataSourceXid":"DS_5d06b8ba-c91b-4c93-b594-92c5009ec67e",
                                             "defaultCacheSize":1,
                                             "deviceName":"Virtual Data Source",
                                             "discardExtremeValues":false,
                                             "discardHighLimit":1.7976931348623157E308,
                                             "discardLowLimit":-1.7976931348623157E308,
                                             "intervalLoggingPeriod":15,
                                             "intervalLoggingSampleWindowSize":0,
                                             "overrideIntervalLoggingSamples":false,
                                             "preventSetExtremeValues":false,
                                             "purgeOverride":false,
                                             "purgePeriod":1,
                                             "readPermission":"",
                                             "setExtremeHighLimit":1.7976931348623157E308,
                                             "setExtremeLowLimit":-1.7976931348623157E308,
                                             "setPermission":"",
                                             "tags":{
                                             },
                                             "textRenderer":{
                                                "type":"BINARY",
                                                "oneColour":"#ff0000",
                                                "oneLabel":"one",
                                                "zeroColour":"blue",
                                                "zeroLabel":"zero"
                                             },
                                             "tolerance":0.0
                                          },
                                    

                                    @phildunlap What is lastSet in this case? It says lastSet is undeclared.

                                    1 Reply Last reply Reply Quote 0
                                    • phildunlapP
                                      phildunlap
                                      last edited by phildunlap

                                      That's the variable name I gave to a binary virtual point that would be in the Set point handler's "Additional Context."

                                      I guess you could in theory have issues then where you wanted the script to be invoked more than once in a fifteen second interval, but at that point you're really on the hook for specifying the logic you need very clearly. It may be easier for your script to use a lock file or some such.

                                      K 1 Reply Last reply Reply Quote 0
                                      • K
                                        khuang @phildunlap
                                        last edited by

                                        @phildunlap Ok, I see what you mean. So if my source point has not changed for 15 seconds, I can treat it as unchanged and do something off of that.
                                        For now, I just created another data point event detector for the source point to detect a state of 0. And when the state is 0, I run a process command that kills the python script. It seems to get the job done, and now when I run "top" I can see the python process going away and back as I toggle the source point.

                                        Thanks for the help guys!

                                        MattFoxM 1 Reply Last reply Reply Quote 0
                                        • MattFoxM
                                          MattFox @khuang
                                          last edited by MattFox

                                          @khuang said in Process Event handler to fire external script:

                                          And when the state is 0, I run a process command that kills the python script.

                                          If you're having to kill the script I suggest you establish some more parameters and make it return/exit after it fires. You don't want errant scripts causing havoc in your system. Scripts should be one shots only.

                                          Do not follow where the path may lead; go instead where there is no path.
                                          And leave a trail - Muriel Strode

                                          K 1 Reply Last reply Reply Quote 0
                                          • phildunlapP
                                            phildunlap
                                            last edited by

                                            Glad you got it figured out! Thanks Fox!

                                            I can treat it as unchanged and do something off of that.

                                            UNCHANGED is a special return value for email handlers, set point handlers, meta points, and point links to cancel whatever would normally occur. So no email, no value set to the target point, no value to the meta point, and no value to the target of the point link.

                                            MattFoxM 1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post