Skip to content

Instantly share code, notes, and snippets.

@dmoruzzi
Created April 26, 2023 03:50
Show Gist options
  • Save dmoruzzi/0c790455eb6bdda28131e3ed9e15c0fa to your computer and use it in GitHub Desktop.
Save dmoruzzi/0c790455eb6bdda28131e3ed9e15c0fa to your computer and use it in GitHub Desktop.

Genesys Cloud Deprecations Monitor

This Perl script is a proof of concept for monitoring the deprecation of Genesys Cloud (formerly Purecloud) features. It fetches the RSS feed of Genesys Cloud's feature deprecations and announcements webpage and compares the results to an internal microservice. If the dates are different, the Perl script will execute a PATCH on the microservice with the lastBuildDate from the vendor and include an authorization token.

This script is not production-ready and is provided as-is without any guarantees or warranty. Use at your own risk. The microservice included in this script is unnecessary and was included only as an idea for maintaining versioning in some enterprise operationals portal. Each enterprise to their own.

The script can be automated with crontab.

Risk

Genesys Cloud Services, Inc. does not officially advertise their RSS feed. Instead, this is included on behalf of their content management system (CMS) PublishPress. As such, this RSS feed may be unavailable in the future. To accommodate this, additional evaluation procedures should be done to ensure that valid XML is being passed.

One source is none. Two is one. Therefore, checking Genesys Cloud's sitemap for the feature deprecation's last modified time should be done as well. This was excluded from the proof of concept.

This script does not have a method to notify of failure to retrieve vendor's RSS feed. This was excluded from the proof of concept.

Requirements

  • Perl 5.10 or higher
  • LWP::UserAgent
  • HTTP::Request
  • JSON
  • XML::Simple
  • Log::Log4perl

Installation

This script requires the following Perl modules:

$ cpan LWP::UserAgent HTTP::Request JSON XML::Simple Log::Log4perl

Make sure you have these modules installed before running the script:

$ perl genesys-deprecations-monitor.pl

Warning

This script is a proof of concept and should not be used in production environments and was instead a quick mock-up explaining how this could be done. This is provided as-is without any guarantees or warranty. Use at your own risk.

#!/usr/bin/perl
use strict;
use warnings;
use LWP::UserAgent;
use HTTP::Request;
use JSON;
use XML::Simple;
use Log::Log4perl qw(:easy);
# Variable configurations
my $internal_endpoint = 'https://example.com/v1/genesys/deprecations-warnings';
my $token = '<internal_endpoint_token>';
my $vendor_endpoint = 'https://help.mypurecloud.com/articles/feature-deprecations/rss/';
# Configure logging
Log::Log4perl->easy_init({
level => $TRACE,
layout => '[%d] [%p] %m%n',
file => '>>monitor.log',
});
# Set up user agent for headless monitoring
my $ua = LWP::UserAgent->new(
ssl_opts => { verify_hostname => 1 },
timeout => 10,
);
# Fetch lastBuildDate from internal endpoint
my $internal_date = fetch_last_build_date($ua, $internal_endpoint);
DEBUG("Fetched lastBuildDate from internal endpoint: $internal_date");
# Fetch lastBuildDate from vendor endpoint
my $vendor_date = fetch_last_build_date($ua, $vendor_endpoint, \&parse_xml);
DEBUG("Fetched lastBuildDate from vendor endpoint: $vendor_date");
# Compare lastBuildDates and execute PATCH on internal endpoint if necessary
if ($internal_date && $vendor_date && $internal_date ne $vendor_date) {
update_last_build_date($ua, $internal_endpoint, $token, $vendor_date);
} elsif ($internal_date && $vendor_date) {
DEBUG("Both internal and vendor endpoints return the same lastBuildDate: $vendor_date. No update required.");
}
# Shutdown logging
Log::Log4perl::Logger->cleanup();
sub fetch_last_build_date {
my ($ua, $endpoint, $parser) = @_;
$parser ||= \&decode_json;
my $response = $ua->get($endpoint);
if ($response->is_success) {
my $data = $parser->($response->decoded_content);
return $data->{content}->{lastBuildDate};
} else {
ERROR("Failed to fetch lastBuildDate from $endpoint: " . $response->status_line);
return;
}
}
sub parse_xml {
my ($content) = @_;
return XMLin($content);
}
sub update_last_build_date {
my ($ua, $endpoint, $token, $date) = @_;
my $data = '{"content":{"lastBuildDate":"' . $date . '"}}';
my $request = HTTP::Request->new('PATCH', $endpoint);
$request->header('Content-Type' => 'application/json');
$request->header('Authorization' => "Bearer $token");
$request->content($data);
my $response = $ua->request($request);
if ($response->is_success) {
INFO("Successfully updated lastBuildDate on $endpoint: $date");
} else {
ERROR("Failed to update lastBuildDate on $endpoint: " . $response->status_line);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment