Skip to content

Instantly share code, notes, and snippets.

@tyzbit
tyzbit / plex-status.js
Last active February 9, 2016 14:31 — forked from Dirrk/plex-status.js
Plex status.js
#!/usr/bin/node
/*
Install nodejs
create directory with this file in it and run the following commands:
npm install wreck@7.0.0 lodash@3.10.1
Setup with crontab:
* * * * * /usr/bin/node /home/dirrk/scripts/plex-info/plex-status.js >> /var/log/plex/plexstatus.log 2>/dev/null
Setup splunk to consume json with timestamp from utc on timestamp field
^(?:(?P<timestamp>\d+\/\d+\/\d+\s+\d+:\d+:\d+) (?:(?P<failed_file>[^:]+): (?P<failure_status>[^:]+): HTTP code (?P<http_code>\d+): \"(?P<http_status>[^"]+)\", (?:.+: (?P<failure_json>{.*})|.+)|(Amazon cloud drive root '(?P<acd_root>.*)': )?(?<acd_status>[\w\s]+)|(?P<file_path>(?:.*\/)?(?<filename>[^\/]+\.[a-z0-9]{3,5}))?[a-zA-Z\/\s\.0-9]*: (?<acd_action>[^\n]+)))?(\n?Transferred:\s+(?<transferred_bytes>\d+)\s+Bytes\s*\(\s*(?<transfer_speed>[\d\.]+) kByte\/s\)\nErrors:\s+(?<errors>\d+)\nChecks:\s+(?<checks>\d+)\nTransferred:\s+(?<files_transferred>\d+)\nElapsed time:\s+((?P<hour>[0-9\.]+)h)?((?P<min>[0-9\.]+)m)?(?P<sec>[0-9\.]*)s)?$
^<W>(?P<timestamp>\d+\-\d+\-\d+\s+\d+:\d+:\d+\.\d+)\s+(?P<server_number>\d+)\s+=>\s+<(?P<connection_number>[^:]+):((?P<user>\w+))?\((?P<userid>[\d\-]+)[^ \n]* (?P<full_message>(.*to (?P<channel>[ \-=\w\#\[\]\{\}\(\)\@\|\'\.]+)\[)?(.*connection: (?P<ipaddress>[0-9\.]+))?(.*version (?P<version>[0-9\.]+))?(.* \((?P<version_full>.*))?.+)
^(?<timestamp>\w+\s+\d+,\s+\d+\s+\d+:\d+:\d+\.\d+)[^\]\n]*\]\s+(?<loglevel>\w+) - (?<full_message>(?:(?:Request: \[(?<request_ip>[^:]+).*Token \((?<username>[^)]+))?(?:\[?(?<status_source>[\w\s]+)((\]|: )))?(?:Adding (?<session_number>\d) sessions\.)?(?:Found session GUID of (?<session_guid>[^\s]+))??(?:Session (?<playback_session_guid>[^\s]+) \((?<playback_session_number>[^\)]+)\) is (?<placyback_session_status>\w+))?(?:using profile (?<transcode_profile>.*))?(?:.*\/transcode\/session\/(?<transcode_session_guid>[^\/]+))?(?:It took (?<time_taken>[\d\.]+) sec to (?<action_taken>.*))?)?(?:Content-Length of (?<file_path>.*\/(?<file_name>[\w\s]+\.(avi|mp4|mkv|m4v|wmv|mpg|mpeg|divx))(\s|$)))?.*)$
[Plex - Top transcoded media]
dispatch.earliest_time = -7d@h
dispatch.latest_time = now
display.general.type = statistics
display.page.search.mode = fast
display.page.search.tab = statistics
display.visualizations.charting.chart = area
display.visualizations.show = 0
request.ui_dispatch_app = search
request.ui_dispatch_view = search
@tyzbit
tyzbit / interactive-tcp.sh
Last active September 21, 2017 03:15
Connect to an arbitrary TCP port to Read/Write. Very basic, will probably break easily but robust enough to test FTP credentials sans FTP
#!/bin/bash
if [ ! -z $2 ]; then
host=$1
port=$2
exec 5<>/dev/tcp/$host/$port
cat <&5 &
trap "exec 5>&- " EXIT
while true; do
read p
echo "$p" >&5
#!/bin/bash
#
# Prints out information from bitcoin-cli about the previous Bitcoin difficulty
# adjustment and the projected difficulty adjustment.
#
# Requires: bitcoin-cli
# jq
# bc
#
#!/bin/bash
# date,wallet_balance,channel_balance,total_capacity,remote_balance,unsettled_balance,sent_balance,received_balance,off_chain_updates,active_nodes,inactive_nodes,pending_channels,limbo_channels,pending_open,pending_close,pending_force_close
lncli="/home/lightning/gocode/bin/lncli"
file="~/lightning-monitor.csv"
# Date
newline="$(date +%s%3N)"
#set the separator to not be space
IFS=""
@tyzbit
tyzbit / bashrc.sh
Created March 9, 2018 22:02
Bash Prompt Timestamp and colored kubectl info
export UPDATE_TIME=0
promhostname=$(hostname | cut -d'.' -f1)
#grab the 8 characters after the first part of the hostname (ABC-lx00000000)
hostname=$(hostname|cut -c9-15|cut -d'.' -f1)
#if the hostname is less than 8 characters, pad it with dashes until it's 8 characters
i=0;while [ $(echo $hostname | wc -m) -le 8 ]; do
[ $i = 0 ] && hostname=$(echo $hostname"-") || hostname=$(echo "-"$hostname); i=$((1-i))
done
@tyzbit
tyzbit / get-lnd-stats.sh
Last active April 5, 2018 16:07
get-lnd-stats - periodically query the lnd daemon for stats, then ship it off to Splunk
#!/bin/bash
token="[SPLUNK_TOKEN_HERE]"
endpoint="http://[SPLUNK_SERVER_HERE]:8088/services/collector/event"
lncli="/home/$USER/gocode/bin/lncli"
commands=(
"getinfo"
"listpeers"
"walletbalance"