0
I'm trying to get a simple log/email alert to fire in Marklogic and am following the examples in the documentation. However I cannot seem to execute an action.

My steps:   
[1] create config and insert.   
[2] create action and insert.   
[3] create rule and insert.

我的警报操作很简单xdmp:log("some message", "alert")。我创建了一个log.xqy并将其加载到 Modules dB 中。当我调用alert:invoke-matching-actions("config uri", fn:doc("/mydocs/doc.xml"), ). 我希望警报操作写入我的日志,但它没有,我似乎无法有意义地调试它。

(:_________**set up config**___________________:)    
xquery version "1.0-ml";      
import module namespace alert = "http://marklogic.com/xdmp/alert" 
      at "/MarkLogic/alert.xqy";      
let $config := alert:make-config(  
      "test-config-uri",
      "test-config-name",
      "Alerting config for test",
        `<alert:options/>`   
)      
return alert:config-insert($config);



(:_______**set up action**___________________:)      
xquery version "1.0-ml";      
import module namespace alert = "http://marklogic.com/xdmp/alert" 
      at "/MarkLogic/alert.xqy";      
let $action := alert:make-action(  
    "test-action-xdmp:log", 
    "log to ErrorLog.txt",
    xdmp:modules-database(),
    xdmp:modules-root(), 
    "/modules/alert/log.xqy",
`<alert:options>`content modified`</alert:options>`           
)      
return  alert:action-insert("test-config-uri", $action);



(:_____**create rule**____________________:)      
xquery version "1.0-ml";      
import module namespace alert = "http://marklogic.com/xdmp/alert" 
      at "/MarkLogic/alert.xqy";      
let $rule := alert:make-rule(  
    "test-rule-name", 
    "test-rule-name-desc",
    0, 
    cts:word-query("Radiohead"),
    "test-action-xdmp:log",
    `<alert:options/>`   
)      
return  alert:rule-insert("test-config-uri", $rule);




(:_______**run rule against content**____________________:)      
xquery version "1.0-ml";      
import module namespace alert = "http://marklogic.com/xdmp/alert" 
  at "/MarkLogic/alert.xqy";      
alert:invoke-matching-actions("test-config-uri", 
      <doc>Radiohead</doc>, <options/>);




(:_______**log.xqy**_______________________________:)      
xquery version "1.0-ml";      
let $msg := "Content was modified. New update alert. "      
let $level := "alert"      
return xdmp:log($msg, $level);
4

1 回答 1

0

我从 QConsole 运行了以下内容,这对我来说效果很好。确保在您的最后正确创建 log.xqy。它必须是模块数据库中与运行该alert:invoke-matching-actions函数的应用服务器关联的文本文件。

(:_________**set up config**___________________:)    
xquery version "1.0-ml";
import module namespace alert = "http://marklogic.com/xdmp/alert" 
      at "/MarkLogic/alert.xqy";      
if (empty(alert:config-get("test-config-uri"))) then
  let $config := alert:make-config(  
      "test-config-uri",
      "test-config-name",
      "Alerting config for test",
      <alert:options/>
  )     
  return alert:config-insert($config)
else ()

;

(:_______**set up action**___________________:)      
xquery version "1.0-ml";      
import module namespace alert = "http://marklogic.com/xdmp/alert" 
      at "/MarkLogic/alert.xqy";
if (empty(alert:get-actions("test-config-uri", "test-action-xdmp:log"))) then
  let $action := alert:make-action(  
    "test-action-xdmp:log", 
    "log to ErrorLog.txt",
    xdmp:modules-database(),
    xdmp:modules-root(), 
    "/modules/alert/log.xqy",
    <alert:options>content modified</alert:options>           
  )      
  return  alert:action-insert("test-config-uri", $action)
else ()

;

(:_____**create rule**____________________:)      
xquery version "1.0-ml";      
import module namespace alert = "http://marklogic.com/xdmp/alert" 
      at "/MarkLogic/alert.xqy";
if (empty(alert:get-all-rules("test-config-uri", cts:word-query("test-rule-name")))) then
  let $rule := alert:make-rule(  
    "test-rule-name", 
    "test-rule-name-desc",
    0, 
    cts:word-query("Radiohead"),
    "test-action-xdmp:log",
    <alert:options/> 
  )      
  return  alert:rule-insert("test-config-uri", $rule)
else ()

;

(:_______**log.xqy**_______________________________:)
let $doc := text {'
  xquery version "1.0-ml";      
  let $msg := "Content was modified. New update alert. "      
  let $level := "alert"      
  return xdmp:log($msg, $level);
'}
return
xdmp:eval(
  '
    xquery version "1.0-ml";
    declare variable $uri external;
    declare variable $doc external;
    xdmp:document-insert($uri, $doc, xdmp:default-permissions())
  ',
  map:new((
    map:entry("uri", "/modules/alert/log.xqy"),
    map:entry("doc", $doc)
  )),
  map:entry("database", xdmp:modules-database())
)

;

(:_______**run rule against content**____________________:)      
xquery version "1.0-ml";      
import module namespace alert = "http://marklogic.com/xdmp/alert" 
  at "/MarkLogic/alert.xqy";      
alert:invoke-matching-actions("test-config-uri", 
      <doc>Radiohead</doc>, <options/>)

于 2018-01-08T19:25:24.723 回答