• 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

    Can you create a global script that will enable the maintenance mode module when a binary data point is true?

    How-To
    2
    4
    1.3k
    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
      KroniK907
      last edited by

      I get alarms from my system, but when I'm tweaking things or working on my system and dont want to get bombarded with alarms, I like to use the maintenance mode module to keep the alarms quiet while I'm working on things. However, this requires going into mango and enabling the maintenance mode manually. I would love to wire in a switch that I can flip to enable maintenance mode. I figure this should be possible using either a data point script or a global script of some kind.

      Is there any script API documentation that shows how to set or unset the maintenance modes from the maintenance module?

      Thanks!

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

        Hi KroniK907, welcome to the forum!

        There is certainly some information that can make this possible, the source code for the module: https://github.com/infiniteautomation/ma-modules-public/tree/main/Maintenance Events

        So, we could find the toggle method to see what it does:
        https://github.com/infiniteautomation/ma-modules-public/blob/main/Maintenance Events/src/com/serotonin/m2m2/maintenanceEvents/MaintenanceEventsDwr.java#L127

        And then we could define a function in our global script like,

        function toggleMaintenanceEvent(xid) {
          var id = com.serotonin.m2m2.maintenanceEvents.MaintenanceEventDao.instance.getIdByXid(xid);
          if(id === null)
            throw "Maintenance Event with XID:" + xid + " not found"
          var rt = com.serotonin.m2m2.maintenanceEvents.RTMDefinition.instance.getRunningMaintenanceEvent(id);
          if(rt === null)
            return "Event is disabled.";
          else
            return rt.toggle();
        }
        

        You could then use a set point event handler (triggered from a state event detector on the point) to enable and disable the maintenance event, like,

        var maintenanceEnabled = toggleMaintenanceEvent("MNT_123");
        if( maintenanceEnabled === false ) //Someone might have toggled it otherwise?
          toggleMaintenanceEvent("MNT_123");
        //else okay, it either threw an error  or returned a string, so let's throw the string!
        else if( typeof maintenanceEnabled === 'string' )
          throw maintenanceEnabled;
        

        and

        var maintenanceEnabled = toggleMaintenanceEvent("MNT_123");
        if( maintenanceEnabled === true )
          toggleMaintenanceEvent("MNT_123");
        //else okay, it either threw an error  or returned a string, so let's throw the string!
        else if( typeof maintenanceEnabled === 'string' )
          throw maintenanceEnabled;
        

        This would be a simple way to figure it out, but we could also use the RT's isEventActive() function in the globally defined function, such that we could just pass a second argument, true / false, and not have to double toggle in the event handler: https://github.com/infiniteautomation/ma-modules-public/blob/main/Maintenance Events/src/com/serotonin/m2m2/maintenanceEvents/MaintenanceEventRT.java#L60

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

          Sorry for the late reply.

          Thank you so much for the help, this was very easy to follow.

          The one thing I'm not clear on is how to call isEventActive()

          I'm guessing that I would use the getMaintenanceEvent(xid) from here: https://github.com/infiniteautomation/ma-modules-public/blob/main/Maintenance Events/src/com/serotonin/m2m2/maintenanceEvents/MaintenanceEventsDwr.java#L52

          Something like this?

          //To toggle off
          var maintEvt = getMaintenanceEvent("MNT_123");
          if (maintEvt.isEventActive())
              toggleMaintenanceEvent("MNT_123");
          
          1 Reply Last reply Reply Quote 0
          • phildunlapP
            phildunlap
            last edited by phildunlap

            You could use that function, but it returns a ProcessResult which would require figuring out how to work with that object. Also you would have to use the package path to the DWR and have an instance of the DWR. Instead, you should get the rt I was referring to the way I did,

            function getMaintenanceEvent(xid) {
              var id = com.serotonin.m2m2.maintenanceEvents.MaintenanceEventDao.instance.getIdByXid(xid);
              if(id === null)
                throw "Maintenance Event with XID:" + xid + " not found"
              var rt = com.serotonin.m2m2.maintenanceEvents.RTMDefinition.instance.getRunningMaintenanceEvent(id);
              if(rt === null)
                return { "isEventActive": function() { return false }}; //disabled events considered inactive?
              else
                return rt;
            }
            

            and then your code could look like,

            var maintEvt = getMaintenanceEvent("MNT_123");
            if (maintEvt.isEventActive())
                maintEvt.toggle();
            

            Also the timing of the original question was inopportune as we added a script utility for Maintenance Events shortly after. It can be used like,

            MaintenanceEventsUtility.isEventActive(xid); //requires maintenance events 3.5.1
            MaintenanceEventsUtility.toggle(xid);
            MaintenanceEventsUtility.setState(xid, boolean); //in 3.5.0 this happens even during validation
            //in 3.5.0 the context name is maintenanceEventsUtility
            

            It also has some CRUD functions exposed, which I would direct you to the code for: https://github.com/infiniteautomation/ma-modules-public/blob/main/Maintenance Events/src/com/infiniteautomation/mango/maintenanceEvents/MaintenanceEventsJavascriptUtility.java

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