102 % of everything is crap I know the law is “90%” of everything is crap. Unfortunately, my percentage calculator isn't in the other 10%. This is a true.

Slides:



Advertisements
Similar presentations
“What do you want me to do now?”
Advertisements

Version Control Systems Phil Pratt-Szeliga Fall 2010.
1Bloom Filters Lookup questions: Does item “ x ” exist in a set or multiset? Data set may be very big or expensive to access. Filter lookup questions with.
Computer Science 101 Web Access to Databases Overview of Web Access to Databases.
Interconnection Protocol Mustafa Kara Term Work.
Safety On The Internet  Usage time  Locations that may be accessed  Parental controls  What information may be shared with others Online rules should.
PerfSONAR Client Construction February 11 th 2010, APAN 29 – perfSONAR Workshop Jeff Boote, Assistant Director R&D.
NETWORK CENTRIC COMPUTING (With included EMBEDDED SYSTEMS)
LIS651 lecture 7 PHP mySQL Thomas Krichel
1 HTML and CGI Scripting CSC8304 – Computing Environments for Bioinformatics - Lecture 10.
Server-side Scripting Powering the webs favourite services.
Designing and Implementing Web Data Services in Perl
Java: Chapter 1 Computer Systems Computer Programming II.
HTTP HTTP stands for Hypertext Transfer Protocol. It is an TCP/IP based communication protocol which is used to deliver virtually all files and other.
PHP meets MySQL.
1 In the good old days... Years ago… the WWW was made up of (mostly) static documents. –Each URL corresponded to a single file stored on some hard disk.
Technology vocabulary slides assignment. Application Definition : A program or group of programs designed for end users. Application software can be divided.
Sublayers Under the Network Layer: BOOTP & DHCP
ITEC 370 Lecture 14 Implementation. Review Questions? Draft of design document on F Brief 3-5 minute work update on F (will continue except for mid-term)
(Chapter 10 continued) Our examples feature MySQL as the database engine. It's open source and free. It's fully featured. And it's platform independent.
1 Basic Perl CGI Programming. 2 Issues How and when your program is invoked. Generating Response –HTTP Headers –HTML (or whatever document type you want)
Real-time multimedia and communication in packet networks Asterisk AGI and Manager Interface.
A Response to Support Look kids Big Ben  3 Introductions  Derick Larson  Support and Training Favorite St. Paul Activity: Watching the pig deliver.
1 © Donald F. Ferguson, All rights reserved.Modern Internet Service Oriented Application Development – Lecture 2: REST Details and Patterns Some.
INFO 637Lecture #71 Software Engineering Process II Product Implementation INFO 637 Glenn Booker.
CSCI 156: Lab 11 Paging. Our Simple Architecture Logical memory space for a process consists of 16 pages of 4k bytes each. Your program thinks it has.
COOKIES AND SESSIONS.
Today… Modularity, or Writing Functions. Winter 2016CISC101 - Prof. McLeod1.
Ch. 23, 25 Q and A (NAT and UDP) Victor Norman IS333 Spring 2015.
/16 Final Project Report By Facializer Team Final Project Report Eagle, Leo, Bessie, Five, Evan Dan, Kyle, Ben, Caleb.
Lecture 5 Page 1 CS 111 Summer 2013 Bounded Buffers A higher level abstraction than shared domains or simple messages But not quite as high level as RPC.
Lesson 11: Web Services and API's
Java Web Services Orca Knowledge Center – Web Service key concepts.
Plus: Exam Scoring How is it done. How many questions are there
* Web Servers/Clients * The HTTP Protocol
How do Web Applications Work?
Tiny http client and server
Unit Testing.
Section 6.3 Server-side Scripting
Academic Talent Search
HW#9 IOS Clues CSCI571 Spring 2017
Lesson 11: Web Services & API's
LCGAA nightlies infrastructure
Introduction to Programming the WWW I
Introduction to Networking
PHP / MySQL Introduction
Naviance: Do What You Are Personality Survey
Internet Control Message Protocol (ICMP)
MVC Framework, in general.
Mary Torjussen A2 ICT Week 1.
Internet Control Message Protocol (ICMP)
Introduction When searching for a new mattress, you have to make sure you know where to go to find the best one. The mattress you sleep on is going to.
Lesson 11: Web Services and API's
Cookies and sessions Saturday, February 23, 2019Saturday, February 23,
Welcome to Naviance at Lowell High School
CS 240 – Advanced Programming Concepts
2.8.2 Being Online Being smart online
Welcome to Naviance at Lowell High School
Network Models.
Booksy University Bug Reports and Feature Requests.
Introduction to AJAX and JSON
Security Principles and Policies CS 236 On-Line MS Program Networks and Systems Security Peter Reiher.
2.8.2 Being Online Being smart online
Digital footprint project
2.8.2 Being Online Being smart online
Being smart online I can discuss what I do online.
A System For Managing Career Learning
* Web Servers/Clients * The HTTP Protocol
Framework Anil
What Can It Do For You? Spira | #InflectraCon
Presentation transcript:

102 % of everything is crap I know the law is “90%” of everything is crap. Unfortunately, my percentage calculator isn't in the other 10%. This is a true story of a real project I did recently.

Asterisk has an API. AWESOME The task: tool to query and update “on call” phone number in Asterisk PABX Asterisk has an API. AWESOME There's a CPAN module. DOUBLE AWESOME We already have a paging system to send SMSes to the right person when something is wrong But other departments want to know who to call in a shit + fan situation. So my task – update the oncall number in Asterisk. There's already an API, with a CPAN module.

It's a piece of cake. Photo: Biyu@flickr

The API “A simple "key: value" line-based protocol. Lines are terminated using CR/LF. We use the term "packet" to describe a set of "key: value" lines that are terminated by an extra CR/LF.” “Generally the client sends Action packets to the Asterisk server, the server performs the requested operation and returns the result in a Response packet.” The Asterisk API is just like HTTP headers. Send a set, get a set back. Each set ends with a blank line. A bit of time with telnet to learn the protocol, and I'd nailed down the task: “DBGet to read the current value, DBPut to update it”. Time to write some code.

The Perl module NAME SYNOPSIS DESCRIPTION Asterisk::Manager - Asterisk Manager Interface SYNOPSIS use Asterisk::Manager; my $astman = new Asterisk::Manager; $astman->user('username'); $astman->secret('test'); $astman->host('localhost'); $astman->connect || die "Could not connect to " . $astman->host . "!\n"; $astman->disconnect; DESCRIPTION This module provides a simple interface to the asterisk manager interface. This is, I tell no lie, the entire documentation for the Perl module. How to connect, and how to disconnect again. At least the source is available.

DBGet Asterisk Manager API Action DBGet Family: <family> Key: <Key> Returns: Response: Error Message: Database entry not found or Response: Success Message: Result will follow Event: DBGetResponse Key: <key> Val: <value> And here's the spec for DBGet (from the wiki). Note how it returns TWO stanzas, not just one. W. T. F. Enterprisy crap 'r' us. I naively tried to send a DBGet using the Perl API. The result - a crash during the “disconnect” phase, because it hadn't parsed the second response off the wire yet. Ouch.

Search the internet for copypasta. Luckily, I've done some PHP – so I know how to deal with something you don't understand. Search the internet for copypasta. Photo: naotakem@flickr

CopyPasta And there it is. On the wiki. Example in Perl (verified in asterisk 1.4.22) use Asterisk::Manager; my $astman = new Asterisk::Manager; $astman->user('<username>'); $astman->secret('<password>'); $astman->host('<host>'); $astman->connect || die $astman->error . "\n"; $astman->sendcommand(Action => 'DBGet', Family => '<family>', Key => '<key>'); my @result = $astman->sendcommand(Event => 'DBGetResponse'); $astman->disconnect; my $value = $result[7]; -> Value 7 is the returned Value And there it is. On the wiki. How to get a value from the DB using Perl. “Verified”. It says it right in the description.

Count the fails But it WORKS Event: DBGetResponse Family: <family> Key: <key> Val: <value> $astman->sendcommand(Action => 'DBGet', Family => '<family>', Key => '<key>'); my @result = $astman->sendcommand(Event => 'DBGetResponse'); $astman->disconnect; my $value = $result[7]; -> Value 7 is the returned Value Even though the protocol claims to be key-value in random order so you can use your favorite language's hash function – in actual fact the order is consistent. And the Perl API uses map and “splitresult”, so it doesn't change the ordering. It might break one day, but for now this works just fine. Has for years. Probably will for many more. So I have a choice – spend 2 minutes copying that code into my script and fixing the indent, or spend hours building something more robust just in case upstream decides to break everyone who already uses this. Guess which strategy lets me get home to my kids with the task finished? But it WORKS