• 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

      You could try an absolute path instead of a ~/, like /home/mango/.ssh/id_rsa

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

        Ok, I think providing the full path worked. Thanks. Interesting that ~/.ssh/id_rsa is provided by default for the private key field but does not work.

        For the set command field, is that where I could execute my shell script? For example:
        0_1548889402147_5cca17f7-f6cd-4ad2-97ed-be287780a1a2-image.png

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

          That should work as usually the home directory is the default location a user logs in as unless stated otherwise in the user profile. This is assuming you've kept it in the /home/mango directory.. All else fails, absolute paths shouldn't fail you.

          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, the script did fire after doing what Phil suggested (to create a Set Point event handler). Changing the value of the target data point caused the set command of the SSH data point to fire. Unfortunately, I get the same errors as before when I had my process event handler.

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

              Since that's the case it's likely best you find the causes of them through virtualenv.
              If they have env paths, echo them in the bash file. This will tell you if your ssh connection is inheriting all of the required information.

              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

                Actually I mispoke - my set point event handler is not firing. It was the old process event handler that was firing that I forgot to deactivate. So now I am trying to set my ssh data point through the set point event handler.

                This is what I have for the set point event handler ("MangoES - Trigger" is the SSH datapoint)"
                0_1548890962362_0504d1b4-bcec-4595-bec3-721f9eaaa6f4-image.png

                It does not look like the event is firing though because my SSH datapoint is N/A.

                0_1548891854421_ff0c2381-501c-49b1-b4fe-6c30d98a956c-image.png

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

                  @khuang Is there no information in logs??
                  Also enable logging on the ssh datasource and tail -f the log file. Would be interesting to see if anything comes through at all.
                  EDIT: check your syslogs as well.

                  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

                    There isn't anything in the sys logs but tail -f for the session log file of the datasource gives me:
                    0_1548894014570_7a83d105-e76e-464c-a7d8-cf3432ccca56-image.png

                    So it does look my test script is running but when I try to flip the bit back to 0 for my ssh data point, it just automatically executes my set point handler again and sets it back to 1. The set point handler shouldn't be activating unless there is a change from 0->1 for my source.

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

                      @khuang Make sure your point handler has normal as 0. also ensure the script to fire box when returning to normal is empty.

                      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
                      • K
                        khuang @MattFox
                        last edited by

                        @mattfox What do you mean by setting the normal as 0? Do you mean creating an inactive action and scripting return 0?

                        Is this what you mean:
                        0_1548894586682_92c73a08-05dc-4533-99b1-bbf44a815772-image.png

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

                          No set inactive action to none. From what I gather you've got the event to fire on change.. What's the logic you're after? if something goes high fire this script? Need more info to diagnose how to set an inactive region.
                          EDIT: Just read above. Get the point in context and check the value,

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

                          That way it checks if the point has changed the right way and then only returns true for that; otherwise it returns false;
                          Ideally just set a high limit and set it to 1. The event will fire on 1 or above and return to normal on zero.

                          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 1
                          • 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
                                            • First post
                                              Last post