• K
    khuang

    Hi,

    I have a data point export (JSON) of a single data point from one mango environment and would like to load it into another mango environment.

    I've found documentation on how to bulk data point import/export from a CSV but mine is JSON formatted.

    EDIT: The only way I found is to use the API but was wondering if there is an alternative.

    Thanks,
    Kevin

    posted in User help read more
  • K
    khuang

    @mattfox Yes, that is a good idea. I will work on thinking of a safe way to exit. My exact use case is that the script will detect people in real time and the only reason why I would want to stop this detection is if a bit flips to zero in the PLC. I was thinking that a safe way to exit could be to continuously poll the data point I want to trigger on to see if it is zero, and if it is zero I exit. However, I would have to make an API call every second. If you have any ideas, please let me know.

    posted in User help read more
  • K
    khuang

    @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!

    posted in User help read more
  • K
    khuang

    @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.

    posted in User help read more
  • K
    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.

    posted in User help read more
  • K
    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.

    posted in User help read more
  • K
    khuang

    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

    posted in User help read more
  • K
    khuang

    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?

    posted in User help read more
  • K
    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.

    posted in User help read more
  • K
    khuang

    @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

    posted in User help read more
  • K
    khuang

    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.

    posted in User help read more
  • K
    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

    posted in User help read more
  • K
    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.

    posted in User help read more
  • K
    khuang

    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

    posted in User help read more
  • K
    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.

    posted in User help read more
  • K
    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

    posted in User help read more
  • K
    khuang

    @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.

    posted in User help read more
  • K
    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.

    posted in User help read more
  • K
    khuang

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

    /usr/local/bin/virtualenvwrapper.sh

    Ok, I'm going to debug just the source command for now.
    If I add #!/bin/bash to the top of my script, it acts as if all my settings in bashrc are ignored. I get an error saying it cannot find the virtualenvwrapper module. Are you suggesting to use #!/bin/bash in order to only run bash and not any of the other shells?

    On the other hand, if I do not have #!/bin/bash:

    1. using:
    source /usr/local/bin/virtualenvwrapper.sh
    

    it seems like it doesn't understand the command

    1. using
    . /usr/local/bin/virtualenvwrapper.sh
    

    it gives a bad substitution error

    posted in User help read more