#!/usr/bin/perl

use 5.014;
use utf8;
use strict;
use warnings;
use Switch;
use JSON;
use HTTP::Request
use LWP::UserAgent;

my $nexthop = shift @ARGV;

my $req = HTTP::Request->new(POST => "https://$nexthop/webhook");
$req->header(
    'Content-Type' => 'application/json; charset=UTF-8',
    'Auth-Token' => 'eiboa1eiwae6Eishebah1AiN7wierop2',
);
$req->content(encode_json({payload => (do {local $/; <>})}));
my $code = LWP::UserAgent->new->request($req)->code;

print "$code\n" unless $code == 201;

switch ($code) {
    case 201                { exit 0 }
    case [415,416,417,501]  { exit 65 }
    case 400                { exit 66 }
    case 503                { exit 69 }
    case 500                { exit 75 }
    case [401,403]          { exit 77 }
    else                    { exit 75 }
}
