Skip to content

Instantly share code, notes, and snippets.

View prestonmcgowan's full-sized avatar

Preston McGowan prestonmcgowan

View GitHub Profile
#!/bin/bash
FILE=/var/log/speedtest/speedtest-`date +"%Y%m"`.results
printf -- '-%.0s' {1..80} >> $FILE
echo >> $FILE
date >> $FILE
/usr/local/bin/speedtest --progress=no >> $FILE
printf -- '-%.0s' {1..80} >> $FILE
echo >> $FILE
IFS=','; for c in `curl -k -s https://localhost:8083/connectors | sed 's/\"//g; s/\[//g; s/\]//g'`; do echo $c; curl -k -s https://localhost:8083/connectors/$c/config > $c.config; done
@prestonmcgowan
prestonmcgowan / confluent--shutdown_all.sh
Created June 10, 2021 12:32
Using the cp-ansible inventory file, shutdown Confluent Services in order
#!/bin/bash
echo "Shutting down control_center"
ansible all -i $1 --limit control_center -m service -a "name=confluent-control-center state=stopped"
sleep 60
echo "Shutting down ksql"
ansible all -i $1 --limit ksql -m service -a "name=confluent-ksql state=stopped"
sleep 60
echo "Shutting down schema_registry"
ansible all -i $1 --limit schema_registry -m service -a "name=confluent-schema-registry state=stopped"
sleep 60
@prestonmcgowan
prestonmcgowan / send-directory-of-syslog.sh
Last active January 19, 2021 14:58
Loop through all the files in a directory, and make use of the send-syslog-data.sh to send the syslog data to Confluent Connect.
#!/bin/bash
## The ./send-syslog-data.sh command below runs as a background task to maximize the cores and ram.
## This script may make the system usable. Change the "&" to a ";" if you want to run it one file at
## a time.
for x in `find ./$1 -type f`; do ./send-syslog-data.sh $x & done
@prestonmcgowan
prestonmcgowan / send-syslog-data.sh
Last active January 19, 2021 14:55
Send data from a file of line delimited syslog to the Confluent Connect Syslog Connector
#!/bin/bash
echo "Sending $1"
while read line; do printf "."; echo $line | nc SYSLOG-CONNECT-FQDN_GOES-HERE 1514; done < $1
echo
@prestonmcgowan
prestonmcgowan / marklogic-password-checker-with-history.xqy
Last active October 30, 2019 19:32
MarkLogic Password Plugin for complexity and history
(: Password rules
:
: at least 12 characters
: has not been used in the previous 24 passwords
: has not been changed in the last day
: does not contain your account or full name
: contains at least three of the the four character groups
: - lower case
: - upper case
: - numbers
@prestonmcgowan
prestonmcgowan / install-valid-tde.xqy
Created October 29, 2019 13:46
Install valid TDE or show validation error
xquery version "1.0-ml";
import module namespace tde = "http://marklogic.com/xdmp/tde"
at "/MarkLogic/tde.xqy";
let $template-uri := "/gds_sample_GeoJSON.tde"
let $template :=
<template xmlns="http://marklogic.com/xdmp/tde">
<description>Example template for GeoJSON documents</description>
<context>/envelope[header/type="geojson"]</context>
@prestonmcgowan
prestonmcgowan / uris-with-element.xqy
Created October 10, 2019 18:55
Find MarkLogic URIs with some element
cts:uris('/sources/', "document", cts:element-query(xs:QName('myElement'),cts:and-query(())))
@prestonmcgowan
prestonmcgowan / zip-documents-to-disk.xqy
Created October 10, 2019 18:54
Zip documents from a MarkLogic database to disk
declare namespace z = "xdmp:zip";
let $parts :=
element z:parts {
for $uri in cts:uris('/sources/', "document", cts:element-query(xs:QName('UploadDocumentMetadata'),cts:and-query(())))[1 to 100]
return (<z:part>{$uri}</z:part>, <z:part>{fn:doc($uri)//UploadedDocumentPath/text()}</z:part>)
}
let $zip := xdmp:zip-create($parts, (
for $p in $parts/z:part
return fn:doc($p) )
@prestonmcgowan
prestonmcgowan / unzip-documents-from-disk.xqy
Created October 10, 2019 18:53
Unzip Documents from disk with MarkLogic
xdmp:document-load("/tmp/docs.zip")
;
declare namespace z = "xdmp:zip";
for $x in xdmp:zip-manifest(doc("/tmp/docs.zip"))//z:part/text()
return
xdmp:document-insert($x, xdmp:zip-get(doc("/tmp/docs.zip"), $x))