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

      I'm pretty confident the scripts work as the scripts execute perfectly on my end. It is only via the process event handler that I get an error. I've added #!/bin/bash to the virtualenvwrapper.sh script and it gives me an error saying:

      Process error: '/usr/bin/python: No module named virtualenvwrapper virtualenvwrapper.sh: There was a problem running the initialization hooks. If Python could not import the module virtualenvwrapper.hook_loader, check that virtualenvwrapper has been installed for VIRTUALENVWRAPPER_PYTHON=/usr/bin/python and that PATH is set properly
      

      This script came with my virtualenv and virtualenvwrapper packages so I should not be editing it. This script uses environmental variables like $HOME in its path, which could contribute to the error, but should I be editing read-only scripts that came with packages that work by default to get things integrated with Mango?

      EDIT: Is there another way to interface my script with Mango other than a process event handler? The trigger is on a data point value change.

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

        Hi khuang,

        EDIT: Is there another way to interface my script with Mango other than a process event handler? The trigger is on a data point value change.

        You could invoke it through an SSH data source / data point, perhaps. Then you should have the environment the user would upon ssh'ing.

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

          I probably should have chimed in this bit earlier:

          I can execute the script just fine manually on the MangoES by running:
          /home/mango/shell_name.sh virtualEnv "python script_name.py arg1 arg2"

          Unfortunately the tokenizing of the process event handler is not the same as the shell that it will pass the arguments to. Quotes and subshells are ignored. The Process Event Handler will pass a list of space delimited strings as arguments to whatever is the first argument.

          cat 'hello.txt' and the error I get is:
          Process error: 'cat: 'Hello.txt': No such file or directory cat.

          Assuredly the cause of this is the single quotes are ignored as shell markup and tokenized into the first argument passed to cat, and there is no file named 'Hello.txt'

          Edit: Note that this is not the case when using the SSH Data Source, where all subshells and quotes and whatnot should be honored appropriately.

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

            Thanks Phil

            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 @phildunlap
              last edited by

              @phildunlap Hi Phil, right now I have a Virtual data source for the purpose of simulation but in production we will have a Modbus I/P datasource. So thinking ahead - say I were to use an ssh data source and data point to trigger my script. Then I would have to set up a point link between the Modbus I/P datapoint to trigger my SSH datapoint which would then trigger my script?

              As for the SSH datapoint, are you suggesting to use either of the query command/settable command to execute my shell script?

              I just want to make sure I understand the full picture before I attempt something that might not be suited for my production environment.

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

                Then I would have to set up a point link between the Modbus I/P datapoint to trigger my SSH datapoint which would then trigger my script? As for the SSH datapoint, are you suggesting to use either of the query command/settable command to execute my shell script?

                You could use a Set Point Event Handler. That's what I'd probably do. My script would look like,

                //Since the command is hardcoded, we don't need to provide a meaningful
                // string to replace VALUE in the set command (see SSH DP help doc)
                return "";
                

                which would send the Set Command and try to get a value, so that you can check the SSH point somewhere to see if the script did what it was supposed to.

                Alternatively you could use the query command, but then the data source will poll with that command. In the SSH data source, after the set command is sent the query command if nonempty is sent as well, and then the response to either is read. Using the set would just be simpler: it will just be the command to invoke.

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

                  @phildunlap I've generated my private key and provided the path to the data source but it's not finding the private key. In my case the server I am ssh'ing to is my MangoES, which also is where my data source lies.

                  0_1548880927540_f9fe533d-7437-4a13-9dc0-3493417e05fe-image.png

                  0_1548881002848_efe2f4b4-2730-44ea-bbad-f48cde3df18a-image.png

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

                    The id_rsa is the private key. So, you'll need to cat id_rsa.pub >> authorized_keys and the provide the path to id_rsa as the private key.

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

                      @phildunlap Yes, I have already done that and my authorized_keys file looks like:

                      ssh-rsa AAAAB3N...N3EU3 mango@mangoES3439
                      

                      In the log it just says:

                      java.io.FileNotFoundException: Private key file not found
                      

                      To test that my key pair works, I've tested ssh IP_MANGOES via shell and I get in without being prompted for the user/pw. It looks like there might be an error with my datasource configuration.

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

                        Phil, woiuld a config file in the .ssh directory for ssh keys work in this case?
                        I do that and try SSH'ing manually first to make sure the remote ID is authenticated and that I go straight through with no issue.

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