Last active
October 10, 2015 14:33
-
-
Save cabrinha/67ef0d7a8ce4e3dcbf82 to your computer and use it in GitHub Desktop.
api wrapper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env perl | |
| use strict; | |
| use warnings; | |
| use v5.22.0; | |
| use Mojo::UserAgent; | |
| use Mojo::URL; | |
| use Data::Dumper; | |
| use Pod::Usage; | |
| use Getopt::Long::Modern qw(auto_help); | |
| # Set some sane defaults | |
| my $rows = 1; | |
| my $date = "today"; | |
| GetOptions( | |
| "f|from=s" => \my $from, | |
| "t|to=s" => \my $to, | |
| "subject=s" => \my $subject, | |
| "fd|from-domain=s" => \my $fdomain, | |
| "td|to-domain=s" => \my $tdomain, | |
| "mid|id=s" => \my $id, # messageID | |
| "host=s" => \my $host, | |
| "oip|ip=s" => \my $ip, # originatingIP | |
| "user-id=s" => \my $uid, | |
| "date=s" => \$date, | |
| "queue-id=s" => \my $qid, | |
| "rows=i" => \$rows, | |
| "spam=s" => \my $spam, # spamResult | |
| "result=s" => \my $result, | |
| "virus=s" => \my $virus, # virusResult | |
| ); | |
| my %options = ( | |
| from => $from, | |
| to => $to, | |
| subject => $subject, | |
| fromDomain => $fdomain, | |
| toDomain => $tdomain, | |
| messageID => $id, | |
| host => $host, | |
| originatingIP => $ip, | |
| userID => $uid, | |
| localID => $qid, | |
| spamResult => $spam, | |
| result => $result, | |
| virusResult => $virus, | |
| ); | |
| my $uri = join( "+", | |
| map { "$_:$options{$_}" } | |
| grep { defined $options{$_} } sort keys %options ); | |
| sub query { | |
| my $url = Mojo::URL->new; | |
| $url->scheme('http'); | |
| $url->host('SOLR_HOSTNAME'); | |
| $url->port('8983'); | |
| # The date needs to be in the path | |
| # Formatted as MMDDYYYY | |
| $url->path("/solr/mail-event-$date/query"); | |
| $url->query( | |
| q => $uri, | |
| rows => $rows, | |
| ); | |
| my $tx = Mojo::UserAgent->new->get($url); | |
| if ( $tx->success ) { | |
| my $res = $tx->res->json; | |
| say Dumper($res); | |
| } | |
| } | |
| query(); | |
| ## Documentation | |
| =head1 NAME | |
| photon - A simple solr API wrapper to safely query event-service | |
| =head1 SYNOPSIS | |
| photon [options] [arguments] | |
| photon --from [email protected] --to [email protected] | |
| Options: | |
| -f, --from MAIL FROM | |
| -t, --to RCPT TO | |
| -sub, --subject SUBJECT | |
| -oi, --orig-ip Originating IP | |
| -di, --dest-ip Destination IP | |
| -mid, --mess-id Message ID | |
| -qid, --queue-id Queue ID | |
| -uid, --user-id User ID | |
| -fd, --from-domain From Domain | |
| -td, --to-domain To Domain | |
| --spam Spam flag (Yes/No) | |
| --result Final message result | |
| --virus Virus flag (Yes/No) | |
| --host Hostname where event took place | |
| --rows How many results to return | |
| =head2 -f, --from | |
| MAIL FROM - Email address the message was sent from | |
| =head2 -t, --to | |
| RCPT TO - Email address of the recipient | |
| =head2 -sub, --subject | |
| SUBJECT - Subject line of the message | |
| =head2 -oi, --orig-ip | |
| X-Originating-Ip - Originating IP address of the sender | |
| =head2 -di, --dest-ip | |
| Destination IP - You will see "destinationIP" listed in the results | |
| =head2 -mid, --mess-id | |
| Message-Id - Message ID | |
| =head2 -qid, --queue-id | |
| Queue ID - Shown in results as localID, typically found in logs as (250 Ok: queued as "QUEUE_ID") | |
| =head2 -uid, --user-id | |
| I have no idea what this field means | |
| =head2 -fd, --from-domain | |
| This shouldn't even be an option | |
| =head2 -td, --to-domain | |
| See: --from-domain | |
| =head2 --spam | |
| X-Spam-Flag - Shown in results as spamResult | |
| =head2 --result | |
| The final result of the message in that event | |
| =head2 --virus | |
| X-Virus-Scanned - Shown as Yes/No | |
| =head2 --host | |
| Hostname of the server the event is taking place on |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment