Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Wiring Websites

David Newhall davidnewhall

💭
Wiring Websites
View GitHub Profile
@davidnewhall
davidnewhall / delete_conversations.applescript
Created Nov 29, 2018
Delete every conversation in Messages.app on Sierra using AppleScript
View delete_conversations.applescript
tell application "Messages"
activate
try
repeat (count of (get every chat)) times
delete item 1 of (get every chat)
tell application "System Events" to tell process "Messages" to keystroke return
end repeat
end try
close every window
end tell
@davidnewhall
davidnewhall / pidfile_snippet.go
Last active Feb 3, 2021
How to write a PID file in Golang.
View pidfile_snippet.go
// Write a pid file, but first make sure it doesn't exist with a running pid.
func writePidFile(pidFile string) error {
// Read in the pid file as a slice of bytes.
if piddata, err := ioutil.ReadFile(pidFile); err == nil {
// Convert the file contents to an integer.
if pid, err := strconv.Atoi(string(piddata)); err == nil {
// Look for the pid in the process list.
if process, err := os.FindProcess(pid); err == nil {
// Send the process a signal zero kill.
if err := process.Signal(syscall.Signal(0)); err == nil {
@davidnewhall
davidnewhall / notify-slack.sh
Created Sep 21, 2017
Simple Nagios Notification Handler to Send Pretty Slack Notifications
View notify-slack.sh
#!/bin/bash
# Send Nagios alert to a Slack Channel.
# Add something like this to Nagios commands.cfg:
#define command {
# command_name notify-host-by-slack
# command_line $USER2$/notify-slack.sh HOST "$CONTACTPAGER$" "$HOSTNAME$" "$TIMET$" "$NOTIFICATIONTYPE$" "$HOSTSTATE$" "$HOSTOUTPUT$" "$LONGHOSTOUTPUT$" "$HOSTNOTESURL$"
# register 1
#}
#define command {
# command_name notify-service-by-slack
@davidnewhall
davidnewhall / check_monit.py
Last active Jul 31, 2016 — forked from mzupan/check_monit.py
Nagios check for monit services going unmonitored
View check_monit.py
#!/usr/bin/env python
# This script will connect to a remove monit instance and report
# CRITICAL if any of the services are currently 'unmonitored'.
import pynagios
import urllib2
import base64
from xml.dom.minidom import parseString
from pynagios import Plugin, make_option, Response