Skip to content

Instantly share code, notes, and snippets.

Last active December 10, 2020 15:56
Show Gist options
  • Save Dyrcona/34f36ba7aacd7b94e31f35c8a54f7f7e to your computer and use it in GitHub Desktop.
Save Dyrcona/34f36ba7aacd7b94e31f35c8a54f7f7e to your computer and use it in GitHub Desktop.
Perl script to test NCIPServer with Evergreen. It sends a LookupUser message to see if the servier is running and configuration is OK.
# ---------------------------------------------------------------
# Copyright © 2019 Jason J.A. Stephenson <>
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# GNU General Public License for more details.
# ---------------------------------------------------------------
use strict;
use warnings;
use LWP::UserAgent;
use HTTP::Request;
use HTML::Entities;
use Getopt::Long;
my $url;
my $fromAgency;
my $toAgency;
my $userBarcode;
GetOptions("url=s" => \$url,
"from-agency=s" => \$fromAgency,
"to-agency=s" => \$toAgency,
"user-barcode=s" => \$userBarcode)
or die("Error in command arguments");
die("Missing required argument(s)") unless($url && $fromAgency && $toAgency && $userBarcode);
$fromAgency = encode_entities($fromAgency);
$toAgency = encode_entities($toAgency);
$userBarcode = encode_entities($userBarcode);
my $data = <<EODATA;
<?xml version="1.0" encoding="utf-8"?>
<NCIPMessage version="" xmlns="">
<UserElementType>User Address Information</UserElementType>
<UserElementType>Block Or Trap</UserElementType>
<UserElementType>Name Information</UserElementType>
<UserElementType>User Privilege</UserElementType>
my $ua = LWP::UserAgent->new;
my $req = HTTP::Request->new(POST => $url);
my $res = $ua->request($req);
if ($res->is_success) {
print $res->content;
} else {
print $res->status_line . "\n";
print $res->content;
Copy link

Dyrcona commented Dec 10, 2020

You can run it like this:

perl --from-agency <WHATEVER> --to-agency <OU_SHORTNAME> --user-barcode <BARCODE OF A PATRON> --url https://host.domain.tld/NCIP/

It should return a XML response with information about the patron. It could return a XML problem response if the patron doesn't exist or whatever. If it returns something other than a XML response, then something is wrong with the configuration on the server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment