Skip to content

Instantly share code, notes, and snippets.

View ableasdale's full-sized avatar

Alex Bleasdale ableasdale

View GitHub Profile
@ableasdale
ableasdale / fn-filter-example.xqy
Created January 10, 2020 12:41
MarkLogic - XQuery fn:filter example
(: Given a sequence from a range lexicon (on the right), pass the sequence to fn:matches and return all instances containing "A7" :)
fn:filter(function($a) { fn:matches($a, "A7") }, cts:element-values(xs:QName("Template")))
@ableasdale
ableasdale / is-journaling-disabled.xqy
Created December 16, 2019 09:53
MarkLogic: output "FAIL" if Journaling is disabled on any database
xquery version "1.0-ml";
import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy";
if(some $i in xdmp:databases() ! admin:database-get-journaling(admin:get-configuration(), .) satisfies ($i eq "off"))
then("FAIL")
else("PASS")
@ableasdale
ableasdale / all-host-configfiles.xqy
Created September 24, 2019 10:38
MarkLogic: retrieve current XML configuration files for all hosts in a cluster
xquery version "1.0-ml";
declare variable $FILES as xs:string+ := ("databases.xml", "hosts.xml", "groups.xml", "assignments.xml", "clusters.xml", "server.xml");
declare variable $FILENAMES as xs:string+ := for $i in $FILES return xdmp:hosts() ! ("file://"||xdmp:host-name(.)||xdmp:data-directory()||"/"||$i);
declare variable $ZIPFILENAME as xs:string := "/tmp/ml-configfiles-"||fn:format-dateTime(fn:current-dateTime(),"[Y01]_[M01]_[D01]_[H01]_[m01]_[s01]")||".zip";
declare function local:write-zipfile() {
let $zip := xdmp:zip-create(
<parts xmlns="xdmp:zip">{for $i in $FILENAMES return element part {$i}}</parts>,
(for $i in $FILENAMES return xdmp:document-get($i))
@ableasdale
ableasdale / sec-users-and-privs.xqy
Created July 10, 2019 15:40
MarkLogic: Get a list of all users and their associated permissions
xquery version "1.0-ml";
declare function local:get-security-users() {
xdmp:eval('xquery version "1.0-ml";
import module namespace sec="http://marklogic.com/xdmp/security" at "/MarkLogic/security.xqy";
declare function local:expand-role-roles($roles){
if(not(empty($roles)))
then(
element ul {attribute class {"parent-roles", $roles},
for $role in $roles
@ableasdale
ableasdale / host-forest-listing.xqy
Created June 11, 2019 18:54
MarkLogic: for a support dump, list the host id and all forest names associated with that host
xquery version "1.0-ml";
(:
: Get the host/forest configuration
:)
declare default element namespace "http://marklogic.com/xdmp/status/forest";
declare variable $path as xs:string := '/Users/ableasdale/Downloads/SuppDump20190414';
@ableasdale
ableasdale / thp-off.sh
Created January 4, 2019 16:16
Linux: Disabling Transparent Huge Pages using grubby
#!/bin/sh
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1&gt;&amp;2
exit 1
fi
for KERNEL in /boot/vmlinuz-*; do
grubby --update-kernel="$KERNEL" --args='transparent_hugepage=never'
done
@ableasdale
ableasdale / preflight-check.xqy
Created September 17, 2018 19:04
MarkLogic: pull details from xdmp:plan for a preflight check
xquery version "1.0-ml";
declare namespace q = "http://marklogic.com/cts/query";
declare variable $QUERY as cts:query := cts:and-query(());
fn:data(xdmp:plan(cts:search(doc(), $QUERY))/q:result/@estimate)
@ableasdale
ableasdale / xquery-console-search-history-no-ridx.xqy
Created September 13, 2018 21:09
MarkLogic: Search Query Console History (no range index)
xquery version "1.0-ml";
declare namespace qc = "http://marklogic.com/appservices/qconsole";
for $i in (//qc:timestamp)
where xs:dateTime($i) ge xs:dateTime("2018-06-26T16:06:49") and xs:dateTime($i) le xs:dateTime("2018-06-26T17:06:49")
return xdmp:node-uri($i)
@ableasdale
ableasdale / qconsole-history-search.xqy
Created September 13, 2018 21:00
MarkLogic: Serch Query Console History
xquery version "1.0-ml";
declare namespace qc = "http://marklogic.com/appservices/qconsole";
cts:search(doc(),
cts:and-query((
cts:element-range-query(xs:QName("qc:timestamp"), ">=", xs:dateTime("2018-06-26T16:06:49")),
cts:element-range-query(xs:QName("qc:timestamp"), "<=", xs:dateTime("2018-06-26T17:06:49"))
))
)
@ableasdale
ableasdale / forest-size-and-reserve.xqy
Created September 12, 2018 12:14
MarkLogic: Calculations for forest sizes (including forest reserve) by host from a support dump
xquery version "1.0-ml";
declare default element namespace "http://marklogic.com/xdmp/status/forest";
declare variable $path as xs:string := '/PATH/TO/support-request-go.xqy.txt';
declare variable $support as document-node()* := xdmp:document-get(
$path,
<options xmlns="xdmp:document-get">
<format>xml</format>