2017-12-27 33 views
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을 만들고 그것을 모듈 dB에로드했습니다. 내가 alert:invoke-matching-actions("config uri", fn:doc("/mydocs/doc.xml"),)을 호출 할 때. 경고 조치가 내 로그에 기록 될 것으로 기대하지만 그렇지 않습니다. 의미있는 디버깅을 할 수 없습니다.Mark Logic의 간단한 문서로드시 발생하는 로그 경고를 어떻게 시작합니까?

(:_________**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); 
+0

위에 나열된 모든 단계에 대해 코드 및 구성 샘플을 포함하십시오. 문서 데이터베이스 이름뿐만 아니라 구성된 트리거 데이터베이스와 트리거에 사용중인 모듈 데이터베이스도 포함하십시오. 여기에는 꽤 많은 움직이는 조각들이 있습니다 - 위의 모든 것에 대해 명확한 선행이 있으면 다른 사람들이 여러분을보다 쉽게 ​​도울 수 있습니다. –

+0

콘텐츠 dB : 음악 (기본 사양으로 생성) 및 기본 모듈 및 트리거 dB를 사용합니다. – Dee

+0

게시물에 모두 서식을 지정하십시오. 의견을 따르는 것은 쉽지 않습니다. –

답변

0

QConsole에서 다음과 같이 실행하면 정상적으로 작동합니다. 마지막에 log.xqy가 제대로 만들어 졌는지 확인하십시오. 그것은 ..

(:_________**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/>) 

HTH 당신이 alert:invoke-matching-actions 기능을 실행할 수있는 응용 프로그램 서버와 연관된 모듈 데이터베이스에 텍스트 파일이어야합니다!

+0

감사합니다. 핵심은 log.xqy가 Modules dB에 있는지 확인하는 것입니다! – Dee

+0

액션을 정의 할 때'xdmp : modules-database()'를 사용하면 yes입니다. :) – grtjn

+0

맞음 :). 모든 시간을 가져 가려고했지만 액션을 처리하는 내장 된 경고 파이프 라인이 있습니다. Marklogic이 Kafka에 게시 할 수있는 알림 옵션이있는 모듈을 갖고 싶습니다. 거기에 대해서도 질문이 있습니다. 이상적으로 '경고'알림 작업은 함께 제공되는 sms/email.xqy 모듈과 비슷한 Kafka 주제로 게시합니다. – Dee