Skip to content

Instantly share code, notes, and snippets.

View maxmanders's full-sized avatar

Max Manders maxmanders

View GitHub Profile
@maxmanders
maxmanders / php_fatal_exception_handler.php
Created October 5, 2012 13:47
PHP Fatal Exception Handler
/*
* Somewhere in their bootstrap code, index.php or wherever, we'd register a shutdown
* callback that is executed when PHP completes serving the request (whether successfully,
* or in the event of a fatal error.
*/
register_shutdown_function('requestShutdown');
function requestShutdown() {
$error = error_get_last();
@maxmanders
maxmanders / gist:4065239
Created November 13, 2012 11:05
Delay start of NSSM created service until the end of a Chef run.
nssm_service "chef-client" do
application "C:/opscode/chef/embedded/bin/ruby.exe"
options "C:/opscode/chef/bin/chef-client -C C:/chef/client.rb -i 1800 -s 120"
end
service "chef-client" do
action :nothing
only_if { WMI::Win32_Service.find(:all).collect{|s| s.name}.include?("chef-client") }
end
@maxmanders
maxmanders / Gemfile
Created November 18, 2012 10:19
Ruby environment
source 'http://rubygems.org'
gem 'rails', '3.2.9'
gem 'sqlite3'
# Use unicorn as the web server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
@maxmanders
maxmanders / gen-iam-cert.sh
Created November 23, 2012 14:46
Generate AWS IAM Certificate
#!/bin/bash
outdir=$1
if [ -z "${outdir}" ]; then
outdir=/tmp/
fi
cd ${outdir}
openssl genrsa -out pk-amazon.pem 2048
59 current_account = ''
60 case line
61 when /^\[(.*)\]$/
62 account_name = (line.match(/^\[(.*)\]$/).captures)[0]
63 p 'account_name = ' + account_name
64 current_account = account_name
65 p 'current_account = ' + current_account
66 @accounts[current_account] = {} unless @accounts.has_key? current_account
67 when /^aws_access_key_id=.*$/
68 aws_access_key_id = (line.match(/^aws_access_key_id=(.*)$/).captures)[0]
@maxmanders
maxmanders / gist:4529353
Created January 14, 2013 11:09
Zenoss 4.2 Collector Problem
1. Installed using auto deploy tool
2. Stopped Zenoss
3. touch /opt/zenoss/etc/DAEMONS_TXT_ONLY
4. Create /opt/zenoss/etc/daemons.txt with:
zenping
zensyslog
zenstatus
zentrap
zenmodeler
zenrender
@maxmanders
maxmanders / gist:4706971
Last active December 12, 2015 03:28
Enumerate Devices in a Zenoss deviceClass
#!/usr/bin/env python
import pprint
import Globals
from Products.ZenUtils.ZenScriptBase import ZenScriptBase
from transaction import commit
dmd = ZenScriptBase(connect=True).dmd
find = dmd.Devices.findDevice
#!/usr/bin/env python
import pprint
import dns.resolver
hostname = "hostname here"
resolver = dns.resolver.Resolver()
resolved_ip_list = []
answers = resolver.query(hostname, 'A')
for rdata in answers:
factory_type_information = (
{
'immediate_view' : 'editHttpResolvingMonitorDataSource',
'actions' :
(
{ 'id' : 'edit',
'name' : 'Data Source',
'action' : 'editHttpResolvingMonitorDataSource',
'permissions' : ( Permissions.view, ),
},
@maxmanders
maxmanders / gist:4952315
Created February 14, 2013 11:51
Zenoss ZenPack Debug
/usr/local/zenoss/common/libexec/check_http_by_hostname.py -H www.some_host_that_resolves.com -p 80 -t 60 -u / -f follow
Exit status is 1 which I had expected to raise an event, with the stdout of the command being the event message
zencommand run -d <device> -v10
...
2013-02-14 11:44:36,515 DEBUG zen.zencommand: running '/usr/local/zenoss/common/libexec/check_http_by_hostname.py -H www.some_host_that_resolves.com -p 80 -t 60 -u / -f follow'
2013-02-14 11:44:36,515 DEBUG zen.zencommand: cmd line: '/bin/sh -c exec /usr/local/zenoss/common/libexec/check_http_by_hostname.py -H www.some_host_that_resolves.com -p 80 -t 60 -u / -f follow'
2013-02-14 11:44:36,540 DEBUG zen.zencommand: Process check_http_by_hostname.py -H www.some_host_that_resolves.com -p 80 -t 60 -u / -f follow started
2013-02-14 11:45:08,918 DEBUG zen.zencommand: Received exit code: 1
2013-02-14 11:45:08,918 DEBUG zen.zencommand: Command: '/bin/sh -c exec /usr/local/zenoss/common/libexec/check_http_by_hostname.py -H www.some_host_that_resolves.c