Skip to content

Instantly share code, notes, and snippets.

@ryanvgates
ryanvgates / haproxy.cfg
Created March 23, 2022 20:15
HA Proxy Multiple Sockets
listen stats # Define a listen section called "stats"
bind :9000 # Listen on port 9000
mode http
stats enable # Enable stats page
stats socket /tmp/haproxy.sock group telegraf mode 660 level user
stats socket /tmp/haproxy_sensu.sock group sensu mode 660 level user
@ryanvgates
ryanvgates / update-sensu-config.sh
Created March 11, 2022 15:42
Update Sensu Config
client_json=/etc/sensu/conf.d/client.json
sudo apt install --assume-yes jq && \
sudo cp $client_json $client_json.backup.$(date +"%Y_%m_%d-%H_%M_%S") && \
contents="$(sudo jq '.client.environment = "new environment"' $client_json)" && \
sudo echo "${contents}" | sudo tee $client_json && \
sudo systemctl restart sensu-client.service && \
sudo systemctl status sensu-client.service
@ryanvgates
ryanvgates / iisreset_and_procdump.ps1
Created March 11, 2022 15:17
Sensu Procdump Check Hook - PowerShell
Get-Location
$scriptPath = $(Split-Path -parent $MyInvocation.MyCommand.Definition)
cd $scriptPath
Get-Location
$main_pid=C:\Windows\system32\inetsrv\appcmd.exe list wps /apppool.name:"mysite" /text:WP.NAME
if (Get-Process procdump -ErrorAction SilentlyContinue) {
Write-Output "Exiting since procdump is running."
exit
}
@ryanvgates
ryanvgates / check_iis_http.json
Created March 11, 2022 15:10
Sensu Procdump Check Hook - sensu
{
"checks": {
"check_iis_http": {
"command": "C:/opt/sensu/embedded/bin/ruby C:/opt/sensu/embedded/bin/check-http.rb -u http://localhost/health",
"handlers": [
"default",
"mailer_detailed"
],
"standalone": true,
"timeout": 15,
@ryanvgates
ryanvgates / solution.cmd
Created February 20, 2022 01:59
Vault on Windows Gotcha - Solution
C:\Users\myuser\Downloads>set VAULT_ADDR=https://my-vault.instance:1234
C:\Users\myuser\Downloads>vault login -method=cert -client-cert=cert.pem -client-key=cert-key.pem
WARNING! The VAULT_TOKEN environment variable is set! This takes precedence
over the value set by this command. To use the value set by this command,
unset the VAULT_TOKEN environment variable or set it to the token displayed
below.
@ryanvgates
ryanvgates / issue.cmd
Created February 20, 2022 01:56
Vault on Windows Gotcha - Issue
C:\Users\myuser\Downloads>set VAULT_ADDR="https://my-vault.instance:1234"
C:\Users\myuser\Downloads>vault login -method=cert -client-cert=cert.pem -client-key=cert-key.pem
failed to create client: parse "https://my-vault.instance:1234": first path segment in URL cannot contain colon
@ryanvgates
ryanvgates / check_disk.json
Created February 11, 2022 21:11
Sensu Check Hook Example
{
"checks":
{
"check_disk":
{
"command": "/etc/sensu/plugins/check-disk.rb -w 3 -c 5 -a 1000 -l //",
"handlers":
[
"default",
"mailer_detailed"
@ryanvgates
ryanvgates / log_cleanup.cmd
Created January 4, 2022 21:56
IIS Log Cleanup One Liner
ROBOCOPY C:\inetpub\logs\LogFiles\W3SVC1 C:\log-files-test /mov /minage:14 & ROBOCOPY C:\inetpub\logs\LogFiles\W3SVC2 C:\log-files-test /mov /minage:14 & del C:\log-files-test /q
@ryanvgates
ryanvgates / remediate.sh
Created December 13, 2021 20:13
CVE-2021-44228 - Remediation in ElasticSearch
echo "-Dlog4j2.formatMsgNoLookups=true" | \
sudo tee -a /etc/elasticsearch/jvm.options && \
sudo cat /etc/elasticsearch/jvm.options && \
sudo systemctl restart elasticsearch && \
ps aux | grep "Dlog4j2.formatMsgNoLookups"
@ryanvgates
ryanvgates / code.rb
Created November 22, 2021 21:42
Chef hardening_rul ip range solution
hardening_rule "Open outbound port #{p} in firewall for Isilon at #{node[:server][:ip_range].gsub("/","-")}" do
direction :out
protocol :udp
port p
destination "#{node[:server][:ip_range]}"
end