deploy/app_specific.rb
# install_alerting is used to define the alerting used for notifications
install_alerting is used to define the alerting used for notifications
install_alerting is used to define the alerting used for notifications
def install_alerting ()
    logger.info "Installing Alerting..\n"
    r = execute_query %Q{
      (: Create the alerting configuration :)
      xquery version "1.0-ml";
      import module namespace alert = "http://marklogic.com/xdmp/alert" at "/MarkLogic/alert.xqy";
      let $config := alert:make-config(
            "http://marklogic.com/demo-cat/notifications",
            "Notifications",
            "Alerting configuration for creating notifications",
              <alert:options/> )
      return alert:config-insert($config);
      (: Create the trigger and associate it with the config :)
      xquery version "1.0-ml";
      import module namespace alert = "http://marklogic.com/xdmp/alert" at "/MarkLogic/alert.xqy";
      import module namespace trgr="http://marklogic.com/xdmp/triggers" at "/MarkLogic/triggers.xqy";
      let $trigger-ids := alert:create-triggers(
        "http://marklogic.com/demo-cat/notifications",
        trgr:trigger-data-event(
          trgr:directory-scope('/demos/', 'infinity'),
          trgr:document-content(("modify")),
          trgr:post-commit()
        )
      )
      return alert:config-insert(
               alert:config-set-trigger-ids(
                  alert:config-get("http://marklogic.com/demo-cat/notifications"),
                  $trigger-ids));
      (: Connect the send email action to the alerting configuration :)
      xquery version "1.0-ml";
      import module namespace alert = "http://marklogic.com/xdmp/alert" at "/MarkLogic/alert.xqy";
      let $action := alert:make-action(
          "send-demo-email",
          "Send an email when a demo is updated",
          xdmp:database('#{@properties["ml.modules-db"]}'),
          '/',
          "/alerting/alert-send-demo-email.xqy",
          <alert:options/> )
      return alert:action-insert("http://marklogic.com/demo-cat/notifications", $action);
      (: Connect the "demo broken" action to the alerting configuration :)
      xquery version "1.0-ml";
      import module namespace alert = "http://marklogic.com/xdmp/alert" at "/MarkLogic/alert.xqy";
      let $action2 := alert:make-action(
          "demo-broken-action",
          "Action to execute when a demo is marked as broken.",
          xdmp:database('#{@properties["ml.modules-db"]}'),
          '/',
          "/alerting/alert-demo-broken-action.xqy",
          <alert:options/> )
      return alert:action-insert("http://marklogic.com/demo-cat/notifications", $action2);
      (: Alerting rule for detecting broken demos. :)
      xquery version "1.0-ml";
      import module namespace alert = "http://marklogic.com/xdmp/alert" at "/MarkLogic/alert.xqy";
      declare namespace jbasic = "http://marklogic.com/xdmp/json/basic";
      let $rule := alert:make-rule(
          "demo-broken-rule",
          "Rule that evaluates a demo to determine if it is broken",
          0, (: equivalent to xdmp:user(xdmp:get-current-user()) :)
          cts:element-value-query(xs:QName("jbasic:status"), "Not Working"),
          "demo-broken-action",
          <alert:options>
            <alert:hostname>#{@properties["ml.referring-host"]}</alert:hostname>
          </alert:options>
          )
      return
      alert:rule-insert("http://marklogic.com/demo-cat/notifications", $rule)
      (: Consider adding any one-off Alerting rules here. :)
      },
     { :db_name => @properties["ml.content-db"] }
   end
def install_alerting ( ) logger . info "Installing Alerting..\n" r = execute_query %Q{

      (: Create the alerting configuration :)
      xquery version "1.0-ml";
      import module namespace alert = "http://marklogic.com/xdmp/alert" at "/MarkLogic/alert.xqy";

      let $config := alert:make-config(
            "http://marklogic.com/demo-cat/notifications",
            "Notifications",
            "Alerting configuration for creating notifications",
              <alert:options/> )

      return alert:config-insert($config);

      (: Create the trigger and associate it with the config :)
      xquery version "1.0-ml";
      import module namespace alert = "http://marklogic.com/xdmp/alert" at "/MarkLogic/alert.xqy";
      import module namespace trgr="http://marklogic.com/xdmp/triggers" at "/MarkLogic/triggers.xqy";


      let $trigger-ids := alert:create-triggers(
        "http://marklogic.com/demo-cat/notifications",
        trgr:trigger-data-event(
          trgr:directory-scope('/demos/', 'infinity'),
          trgr:document-content(("modify")),
          trgr:post-commit()
        )
      )

      return alert:config-insert(
               alert:config-set-trigger-ids(
                  alert:config-get("http://marklogic.com/demo-cat/notifications"),
                  $trigger-ids));


      (: Connect the send email action to the alerting configuration :)
      xquery version "1.0-ml";
      import module namespace alert = "http://marklogic.com/xdmp/alert" at "/MarkLogic/alert.xqy";

      let $action := alert:make-action(
          "send-demo-email",
          "Send an email when a demo is updated",
          xdmp:database('#{@properties["ml.modules-db"]}'),
          '/',
          "/alerting/alert-send-demo-email.xqy",
          <alert:options/> )
      return alert:action-insert("http://marklogic.com/demo-cat/notifications", $action);

      (: Connect the "demo broken" action to the alerting configuration :)
      xquery version "1.0-ml";
      import module namespace alert = "http://marklogic.com/xdmp/alert" at "/MarkLogic/alert.xqy";

      let $action2 := alert:make-action(
          "demo-broken-action",
          "Action to execute when a demo is marked as broken.",
          xdmp:database('#{@properties["ml.modules-db"]}'),
          '/',
          "/alerting/alert-demo-broken-action.xqy",
          <alert:options/> )
      return alert:action-insert("http://marklogic.com/demo-cat/notifications", $action2);


      (: Alerting rule for detecting broken demos. :)
      xquery version "1.0-ml";
      import module namespace alert = "http://marklogic.com/xdmp/alert" at "/MarkLogic/alert.xqy";
      declare namespace jbasic = "http://marklogic.com/xdmp/json/basic";

      let $rule := alert:make-rule(
          "demo-broken-rule",
          "Rule that evaluates a demo to determine if it is broken",
          0, (: equivalent to xdmp:user(xdmp:get-current-user()) :)
          cts:element-value-query(xs:QName("jbasic:status"), "Not Working"),
          "demo-broken-action",
          <alert:options>
            <alert:hostname>#{@properties["ml.referring-host"]}</alert:hostname>
          </alert:options>
          )
      return
      alert:rule-insert("http://marklogic.com/demo-cat/notifications", $rule)

      (: Consider adding any one-off Alerting rules here. :)

      } , { :db_name => @properties [ "ml.content-db" ] } end
install_alerting is used to define the alerting used for notifications
install_alerting is used to define the alerting used for notifications