From 72ca285f0260813876c8532ac058d1e5f629f5c5 Mon Sep 17 00:00:00 2001 From: Georg Pfuetzenreuter Date: Thu, 16 Jan 2025 23:58:36 +0100 Subject: [PATCH] Initialize Signed-off-by: Georg Pfuetzenreuter --- Makefile | 23 +++++++++++++++++++++++ README.txt | 1 + rootail.pl | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 Makefile create mode 100644 README.txt create mode 100755 rootail.pl diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..7652a98 --- /dev/null +++ b/Makefile @@ -0,0 +1,23 @@ +# Makefile for rootail +# +# Copyright 2024, Georg Pfuetzenreuter +# +# Licensed under the EUPL, Version 1.2 or - as soon they will be approved by the European Commission - subsequent versions of the EUPL (the "Licence"). +# You may not use this work except in compliance with the Licence. +# An English copy of the Licence is shipped in a file called LICENSE along with this applications source code. +# You may obtain copies of the Licence in any of the official languages at https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12. + +PREFIX=/usr/local +BINDIR=$(PREFIX)/bin +MANDIR=$(PREFIX)/man +SYSCONFDIR=$(PREFIX)/etc + +usage: + @echo 'Available targets: "install", "uninstall"' + +install: + install -d '$(DESTDIR)$(BINDIR)' + install rootail.pl '$(DESTDIR)$(BINDIR)/rootail' + +uninstall: + rm '$(BINDIR)/rootail' diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..0282a35 --- /dev/null +++ b/README.txt @@ -0,0 +1 @@ +Simple tool which listens to rabbit.opensuse.org (aka "roo") and prints all messages in a human friendly format. diff --git a/rootail.pl b/rootail.pl new file mode 100755 index 0000000..7bfc4d5 --- /dev/null +++ b/rootail.pl @@ -0,0 +1,51 @@ +#!/usr/bin/perl -W +# Simple tool which listens to rabbit.opensuse.org and prints all messages in a human friendly format. +# Copyright 2024, Georg Pfuetzenreuter +# +# Licensed under the EUPL, Version 1.2 or - as soon they will be approved by the European Commission - subsequent versions of the EUPL (the "Licence"). +# You may not use this work except in compliance with the Licence. +# An English copy of the Licence is shipped in a file called LICENSE along with this applications source code. +# You may obtain copies of the Licence in any of the official languages at https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12. + +use 5.26.0; # Leap 15.6 + +use Net::AMQP::RabbitMQ; +use JSON::PP; +use Try::Tiny; + +my $mq = Net::AMQP::RabbitMQ->new(); + +$mq->connect( + 'rabbit.opensuse.org', { + user => 'opensuse', + password => 'opensuse', + ssl => 1, + ssl_cacert => '/etc/ssl/ca-bundle.pem', + } +); + +$mq->channel_open(1); +my $exchange = $mq->exchange_declare(1, 'pubsub', { + durable => 1, + exclusive => 1, + passive => 1, + } +); + +my $queue = $mq->queue_declare(1, ''); +$mq->queue_bind(1, $queue, 'pubsub', '#'); +$mq->consume(1, $queue); + + +while ( my $message = $mq->recv() ) +{ + print "\n=== MESSAGE ===\n"; + try { + my $json = 'JSON::PP'->new->pretty; + print($json->encode($json->decode($message->{'body'}))); + } catch { + print "$message->{'body'}\n"; + }; +} + +$mq->disconnect();