Skip to content

Instantly share code, notes, and snippets.

View ravnx's full-sized avatar

Michael Palmer ravnx

View GitHub Profile
@ravnx
ravnx / canary.pl
Created September 11, 2025 15:20
Mojolicious Service to Check if a host has a port open
#!/usr/bin/perl -w
# This mojo will just check for an open port.
# I use this with nagios to alert me if a firewalled webserver is open to the public internet.
# I run this in a nano cloud instance off network. I use nginx to serve it, and hypnotoad to run it.
# Nagios calls it like "http://foo.app.com/check?host=1.2.3.4&port=443&key=abc123"
#
# You can setup a nagios command like this:
# define command {
# command_name check_api_port_open
# command_line /usr/bin/curl -s "https://foo.app.com/check?host=$HOSTADDRESS$&port=443" | /usr/bin/grep -q '"status":"open"' && echo "Port 443 is OPEN" && exit 2 || echo "Port 443 is closed" && exit 0
@ravnx
ravnx / check-stale-calls.pl
Created September 23, 2024 16:38
Parse PJSIP channels, looking for calls over an hour, alert the admin, cancel some conference bridged Sangoma app calls
#!/usr/bin/perl -w
# This script will run and parse the command pjsip show channels and check for stale calls that are more than an hour old
# and print to the console the channel number and the time the call has been up for, this is mostly a fix for Sangoma App,
# which has a bug when "bridging" a call, since there is no attended transfer, the call will stay up forever if the conference
# bug hits. Hopefully sangoma will fix this, but for now, to save money on long distance calls, we'll just hang up the call if it
# meets criteria. This script will also email the admin if a call is found to be stale, and not ignored. The script will also
# disconnect a conference call. We had a customer mostly conferencing in a CC processor, so we match on the route being specific to
# the conference bridge, that way we can auto cancel it. Otherwise we'll just alert the admin.
use strict;
use MIME::Lite;
@ravnx
ravnx / today-dnd.pl
Last active January 20, 2024 17:14
Pull a DND report from FreePBX for the current day, or specified day for a user extension. Send via email.
#!/usr/bin/perl -w
# This will search the CDR logs for DND toggles for a user.
# Run it from cron if you want, its quiet. If you don't specify a date,
# it will pull today's date.
use strict;
use MIME::Lite;
use Time::Local;
my $ext = $ARGV[0] or die "Must provide extension number";
@ravnx
ravnx / check-pbx-outage.pl
Created January 14, 2024 21:36
Checks Asterisk/FreePBX for more than x phones offline, if we have an outage, switch the Call Flow Control to NIGHT. Switches back to DAY on recovery.
#!/usr/bin/perl -w
# This script will check for if more than $maxoffline phones are offline and
# change the first daynight mode via asterisk if we go over the limit, and alert the user
# Set this up in crontab to run during business hours. This probably could be done safer, and better
# using the AMI interface. But needed something done during an outage, so this got hacked together.
use strict;
use MIME::Lite;
# debug mode
my $debug = $ARGV[0] || 0;
@ravnx
ravnx / status2json.py
Last active February 6, 2025 06:37 — forked from alexwright/status2json.py
Parse the Nagios status.dat and poop out some JSON
#!/usr/bin/python3
"""
This script will dump host stats from your Nagios4 status.dat as JSON.
You can put this in your /usr/lib/cgi-bin/nagios4 directory and chmod +x this file,
then, to access it remotely use python requests:
r = requests.get('https://nagiosinstall-location.com/nagios4/cgi-bin/status2json.py', auth=HTTPDigestAuth(user,pass))
print(r.json())
You might need to add .py to your http.conf cgi handlers.
@ravnx
ravnx / yealink-phonebook.php
Created August 20, 2020 22:38
Yealink Phonebook XML, quick and dirty.
@ravnx
ravnx / polycomPhonebook.pl
Created August 20, 2020 22:32
Polycom Directory of all extensions for IP650 for Asterisk
#!/usr/bin/perl -w
# Quick script to hack out a directory for a mac address. I use it for the
# receptionist's BLF on her IP650 with sidecars.
use strict;
use Polycom::Contact::Directory;
use DBI;
# Grab the MAC address from ARGV and make a file
my $mac = $ARGV[0] or die "No MAC Specified\n";
my $contactFile = "/tftpboot/polycom/contacts/$mac-directory.xml";
#!/usr/bin/perl -w
# This perl script will do a quick and dirty parse from
# outlook vcal to evolution ical format
# Last Update:Thu Feb 05 11:49:59 CST 2004
## New note: Putting this here for archival purposes. Not even sure if outlook uses vcs anymore.
use strict;
my $file = $ARGV[0] or die "No filename specified";
die if (!-e $file);
my $newfile = $file;

Keybase proof

I hereby claim:

  • I am ravnx on github.
  • I am michaelp713 (https://keybase.io/michaelp713) on keybase.
  • I have a public key whose fingerprint is A8EB 25D7 BF9C 8EDB 4C37 E855 6EDA 5B69 4ECB F69E

To claim this, I am signing this object: