Skip to content

Instantly share code, notes, and snippets.

@reyjrar
reyjrar / http_ping.pl
Created July 5, 2011 18:59
http_ping
#!/usr/bin/perl
#
# HTTP "PING" Program.
# Allows someone to check latency to a webserver.
#
# Code by Brad Lhotsky <brad@divisionbyzero.net>
# And Mark Thomas <mark@ackers.net>
#
# Distributed under the same license as perl itself.
#
@reyjrar
reyjrar / dns-query-response-density.r
Created July 7, 2011 21:21
Probability Density of DNS Query/Response times
# Connect to Database
pgDrv <- dbDriver("PostgreSQL")
dbh <- dbConnect(pgDrv, host="", dbname="dnsmonitor", user="dnsmon", password="")
# Retrieve Statistics from DB
stats <- dbGetQuery(dbh, "select * from packet_timing")
# Close the Database Connection and free variables
dbDisconnect(dbh)
rm(dbh)
@reyjrar
reyjrar / DNS-A-AAAA.r
Created July 8, 2011 02:05
Evaluation of IPv6 readiness by looking at "A" and "AAAA" DNS Queries
# Library Loading
library("RPostgreSQL");
library("car");
library("reshape");
# Connect to Database
pgDrv <- dbDriver("PostgreSQL")
dbh <- dbConnect(pgDrv, host="localhost", dbname="dnsmonitor", user="dnsmon", password="tooEasy")
# Retrieve Statistics from DB
@reyjrar
reyjrar / DNS-Query-NX.r
Created July 8, 2011 02:09
Query vs NX Relationships
# Library Loading
library("RPostgreSQL");
library("car");
# Connect to Database
pgDrv <- dbDriver("PostgreSQL")
dbh <- dbConnect(pgDrv, host="localhost", dbname="dnsmonitor", user="dnsmon", password="tooEasy")
# Retrieve Statistics from DB
stats <- dbGetQuery(dbh, "select client.id, client.ip, sum(queries) as queries, sum(nx) as nx, sum(answers) as answers, sum(errors) as errors, count(distinct day) as days_active
@reyjrar
reyjrar / request-to-rule.pl
Created August 4, 2011 17:54
Generate Snort Signature from a HTTP Request
#!/usr/bin/env perl
use strict;
use warnings;
use HTTP::Status;
use URI;
use Snort::Rule;
@reyjrar
reyjrar / moosex-poe-test.pl
Created September 29, 2011 21:45
MooseX::POE Testing
#------------------------------------------------------------------------#
package base;
use MooseX::POE;
with qw( MooseX::POE::Aliased );
event process => sub {
my ($self,$thing) = @_[OBJECT,ARG0];
print "base::process called with $thing\n";
};
@reyjrar
reyjrar / stdout.pm
Created October 5, 2011 20:54
MooseX::POE Simple STDOUT Plugin
package dns::monitor::plugin::sniffer::log::dest::stdout;
use Moose;
extends 'dns::monitor::plugin::sniffer::log';
sub write {
my ($self,$line) = @_;
print $line,"\n";
@reyjrar
reyjrar / dns-monitor-deploy.sh
Created October 8, 2011 16:50
Script using svnutils
#!/bin/bash
BINDIR="/usr/local/sbin"
SVNURL="file:///repo/projects/dns-monitor"
TARGET="/opt/www/dns-monitor"
$BINDIR/svncheckrel $SVNURL $TARGET
rc=$?;
if [ "$rc" -eq "0" ]; then
@reyjrar
reyjrar / syslog-hosts-carbon.sh
Created November 19, 2011 01:51
log the number of distinct hosts communicating with syslog in the past 60 minutes
#!/bin/sh
# Assumes /var/log/remote/%HOSTNAME/ configuration for central logger
#
# collect data
time=`date +%s`;
distinct=`find /var/log/remote -mmin -60 | cut -d/ -f5| sort -u |wc -l`
# send it!
echo "syslog.distinct_hosts $distinct $time" | nc graphite 2003
@reyjrar
reyjrar / syslog-archive.sh
Created November 19, 2011 04:11
Manage /var/log/remote/ syslog storage, compressing and pruning older files.
#!/bin/sh
#
# Script to manage syslog storage capacity
# Remove anything older than 1 year
find /var/log/remote/ -mindepth 2 -mtime +365 -type f -exec rm '{}' \;
# Remove empty directories
find /var/log/remote/ -type d -empty -exec rmdir '{}' \;