Skip to content

Instantly share code, notes, and snippets.

View PowerShell Zabbix API Example.ps1
if(!$credential){
$credential = Get-Credential
}
$baseurl = 'http://zabbix.global.root'
$params = @{
body = @{
"jsonrpc"= "2.0"
"method"= "user.login"
"params"= @{
"user"= $credential.UserName
@Sam-Martin
Sam-Martin / Delete-LowQualityPlexDuplicates.ps1
Created Apr 15, 2018
Delete Lower Quality Plex Duplicates
View Delete-LowQualityPlexDuplicates.ps1
$Server='192.168.1.9:32400'
$PlexToken = 'FGir5aQ5yfpRZZ4ZqxAg'
$libraries = Invoke-RestMethod -Uri "http://$server/library/sections/all?X-Plex-Token=$PlexToken"
$VideoLibraries = $libraries.MediaContainer.Directory | ?{$_.type -eq 'show'}
$Resolutions = @{
"sd" = 1
"420" = 10
"720" = 20
"1080" = 30
}
@Sam-Martin
Sam-Martin / Invoke-KMSEncrypt-Example.ps1
Last active Jun 16, 2020
PowerShell Example for using Invoke-KMSEncrypt and Invoke-KMSDecrypt
View Invoke-KMSEncrypt-Example.ps1
# Stolen from http://ctrlf5.net/?p=263 and http://www.dailycoding.com/posts/convert_image_to_base64_string_and_base64_string_to_image.aspx
function ConvertFrom-StringToMemoryStream{
param(
[parameter(Mandatory)]
[string]$InputString
)
$stream = New-Object System.IO.MemoryStream;
$writer = New-Object System.IO.StreamWriter($stream);
$writer.Write($InputString);
@Sam-Martin
Sam-Martin / Test Kitchen Add Vagrant Disks.md
Last active Mar 21, 2020
Test Kitchen VagrantFile.rb to add disks & test_helper.bash to format them
View Test Kitchen Add Vagrant Disks.md

Use these two files to add disks to your VMs (here adding three disks) when Kitchen spins up Vagrant boxes.

  • test_helper.bash (add to your bats test with load test_helper)
  • vagrantfile.rb (add to your .kitchen.yml using)
---
driver:
  name: vagrant
  vagrantfiles: 
      - vagrantfile.rb
@Sam-Martin
Sam-Martin / Cmdline example
Created Jan 26, 2020
Get Media Language Recursively
View Cmdline example
find . -iregex ".*.\(mp4\|mkv\)" -exec ~/medialanguage.sh "{}" \; | jq '. | select(.Languages | index("English") | not)'
@Sam-Martin
Sam-Martin / userdata.sh
Created Nov 14, 2019
EC2 Userdata for proxy setup of SSM Agent on Amazon Linux 2
View userdata.sh
#!/usr/bin/env bash
mkdir -p /etc/systemd/system/amazon-ssm-agent.service.d
echo "[Service]" > /etc/systemd/system/amazon-ssm-agent.service.d/override.conf
echo 'Environment="https_proxy=http://proxy:3128"' >> /etc/systemd/system/amazon-ssm-agent.service.d/override.conf
echo 'Environment="http_proxy=http://proxy:3128"' >> /etc/systemd/system/amazon-ssm-agent.service.d/override.conf
echo 'Environment="no_proxy=169.254.169.254"' >> /etc/systemd/system/amazon-ssm-agent.service.d/override.conf
chmod 777 /etc/systemd/system/amazon-ssm-agent.service.d/override.conf
systemctl stop amazon-ssm-agent
systemctl daemon-reload
systemctl restart amazon-ssm-agent
@Sam-Martin
Sam-Martin / get_all_lambda_invocation_stats.py
Created Oct 3, 2019
Sort lambda functions by invocations
View get_all_lambda_invocation_stats.py
import sys
import boto3
import datetime
cw = boto3.client('cloudwatch')
list_metrics_paginator = cw.get_paginator('list_metrics')
function_stats = []
@Sam-Martin
Sam-Martin / Clone DynamoDB.py
Created May 15, 2019
Download and Restore DynamoDB
View Clone DynamoDB.py
aws dynamodb scan --table-name TABLE > export.json
import json
import boto3
dynamo = boto3.client('dynamodb')
TABLE_NAME = 'TABLE_NAME'
JSON_PATH = '/Users/USERNAME/git/GitHub/dynamodump/export.json'
with open(JSON_PATH, 'r') as file:
data = file.read()
parsed_file = json.loads(data)
for item_to_import in parsed_file['Items']:
@Sam-Martin
Sam-Martin / RightGIF Integration for HipChat using AWS Lambda.py
Created Apr 26, 2016
RightGIF Integration for HipChat using AWS Lambda
View RightGIF Integration for HipChat using AWS Lambda.py
import urllib
import urllib2
import json
def lambda_handler(event, context):
url = 'https://rightgif.com/search/web'