diff options
74 files changed, 7515 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..7c3dd66 --- /dev/null +++ b/Makefile @@ -0,0 +1,61 @@ +NAME=mon +SHORTNAME=m +all: version documentation perltidy +version: + cut -d' ' -f2 debian/changelog | head -n 1 | sed 's/(//;s/)//' > .version +perltidy: + find . -name \*.pm | xargs perltidy -i 2 -b + perltidy -b $(NAME) + find . -name \*.bak -delete +documentation: + pod2man --release="$(NAME) $$(cat .version)" \ + --center="User Commands" ./docs/$(NAME).pod > ./docs/$(NAME).1 + pod2text ./docs/$(NAME).pod > ./docs/$(NAME).txt + gzip -c ./docs/$(NAME).1 > ./docs/$(NAME).1.gz +install: deinstall + test ! -d $(DESTDIR)/usr/bin && mkdir -p $(DESTDIR)/usr/bin || exit 0 + test ! -d $(DESTDIR)/usr/share/$(NAME) && mkdir -p $(DESTDIR)/usr/share/$(NAME) || exit 0 + test ! -d $(DESTDIR)/usr/share/$(NAME)/examples && mkdir -p $(DESTDIR)/usr/share/$(NAME)/examples || exit 0 + test ! -d $(DESTDIR)/usr/share/$(NAME)/contrib && mkdir -p $(DESTDIR)/usr/share/$(NAME)/contrib || exit 0 + test ! -d $(DESTDIR)/usr/share/man/man1 && mkdir -p $(DESTDIR)/usr/share/man/man1 || exit 0 + cp $(NAME) $(DESTDIR)/usr/bin + cp $(NAME) $(DESTDIR)/usr/bin/$(SHORTNAME) + cp ./mi $(DESTDIR)/usr/bin + cp -r ./lib $(DESTDIR)/usr/share/$(NAME)/ + cp ./.version $(DESTDIR)/usr/share/$(NAME)/version + cp ./$(NAME).conf $(DESTDIR)/usr/share/$(NAME)/examples/$(NAME).conf.sample + cp ./ca.pem $(DESTDIR)/usr/share/$(NAME)/ca.pem + cp -R ./contrib/* $(DESTDIR)/usr/share/$(NAME)/contrib + cp ./docs/$(NAME).1.gz $(DESTDIR)/usr/share/man/man1/$(NAME).1.gz + test ! -z "$(DESTDIR)" && find $(DESTDIR) -name .\*.swp -delete || exit 0 +deinstall: + test -f $(DESTDIR)/usr/bin/$(NAME) && rm $(DESTDIR)/usr/bin/$(NAME) && rm $(DESTDIR)/usr/bin/$(SHORTNAME) && rm $(DESTDIR)/usr/bin/mi || exit 0 + test -d $(DESTDIR)/usr/share/$(NAME) && rm -r $(DESTDIR)/usr/share/$(NAME) || exit 0 + test -f $(DESTDIR)/usr/share/man/man1/$(NAME).1.gz && rm -f $(DESTDIR)/usr/share/man/man1/$(NAME).1.gz || exit 0 +uninstall: deinstall +clean: + test -d debian/$(NAME)/usr && rm -Rf debian/$(NAME)/usr || exit 0 +dch: + dch -i +deb: + dpkg-buildpackage -uc -us +rpm: deb + alien -r --generate ../$(NAME)_$$(cat ./.version)_all.deb + cp redhat-specs-add.txt rpm.specs + sed "s/%%{ARCH}/noarch/" $$(pwd)/$(NAME)-$$(cat ./.version)/*.spec >> rpm.specs + mv rpm.specs $$(pwd)/$(NAME)-$$(cat ./.version)/*.spec + rpmbuild --buildroot $$(pwd)/$(NAME)-$$(cat ./.version) -ba $$(pwd)/$(NAME)-$$(cat ./.version)/*.spec +release: dch version + git commit -a -m 'New release' + bash -c "git tag $$(cat .version)" + git push --tags + git push origin master +clean-top: + rm -f ../$(NAME)_*.tar.gz || exit 0 + rm -f ../$(NAME)_*.dsc || exit 0 + rm -f ../$(NAME)_*.changes || exit 0 + rm -f ../$(NAME)_*.deb || exit 0 + rm -f ../$(NAME)-*.rpm || exit 0 +dotest: + sh -c 'cd ./t;make' + diff --git a/README.md b/README.md new file mode 100644 index 0000000..2b213c1 --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +mon +==== + +The humble monitoring API tool. + +This tool assists you to manage monitoring configurations via the +RESTlos API. + +Please checkout manual pages at ./docs or man mon. @@ -0,0 +1 @@ +I am invalid, fill me diff --git a/contrib/zsh/_mon.zsh b/contrib/zsh/_mon.zsh new file mode 100644 index 0000000..3770c60 --- /dev/null +++ b/contrib/zsh/_mon.zsh @@ -0,0 +1,46 @@ +#compdef m mon + +get_options() { + elements=`${words[1,$[${CURRENT}-1]]} --dry --nocolor 2>&1` + if [ $? -ne 0 ]; then + elements="" + fi + + echo `echo $elements | tr '\n' ' '` +} + +_mon() { + local curcontext="$curcontext" state line + typeset -A opt_args + + case $words[2] in + getfmt) + if [ $CURRENT -eq 5 ]; then + compadd "$@" "where" + return + fi + ;; + post|put) + if [ $CURRENT -eq 4 ]; then + compadd "$@" "from" + return + fi + ;; + delete|edit|get|insert|update|view) + if [ $CURRENT -eq 4 ]; then + compadd "$@" "where" + return + fi + ;; + esac + + VALUES="`get_options`" + if [ -z "${VALUES}" ]; then + _files + else + ARGS=(${=VALUES}) + compadd "$@" ${ARGS[@]} + fi +} + +_mon "$@" diff --git a/debian/README b/debian/README new file mode 100644 index 0000000..41fc005 --- /dev/null +++ b/debian/README @@ -0,0 +1,6 @@ +The Debian Package mon +---------------------------- + +This is just a humble monitoring api tool. + + -- Paul Buetow <paul@buetow.org> Sun, 08 Apr 2012 15:23:53 +0200 diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..22d063a --- /dev/null +++ b/debian/changelog @@ -0,0 +1,5 @@ +mon (1.0.0) stable; urgency=low + + * Initial + + -- Paul Buetow <paul@buetow.org> Fri, 02 Jan 2015 13:50:50 +0100 diff --git a/debian/compat b/debian/compat new file mode 100644 index 0000000..45a4fb7 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +8 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..9d5d0e0 --- /dev/null +++ b/debian/control @@ -0,0 +1,16 @@ +Source: mon +Section: utils +Priority: optional +Maintainer: Paul Buetow <paul@buetow.org> +Build-Depends: perl, perltidy, alien, rpm +Standards-Version: 3.9.2 +Homepage: http://mon.buetow.org +Vcs-Git: https://github.com/rantanplan/mon +Vcs-Browser: https://github.com/rantanplan/mon + +Package: mon +Architecture: all +Depends: ${perl:Depends}, libwww-perl, libtime-modules-perl, libconfig-json-perl, libio-socket-ssl-perl, libunix-syslog-perl, libjson-xs-perl, libterm-readline-gnu-perl +Recommends: ca-root-cert, vim +Description: A simple monitoring API tool + Uses the RESTlos monitoring API to configure monitoring stuff. diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 0000000..9be5c7f --- /dev/null +++ b/debian/copyright @@ -0,0 +1,30 @@ +Format: http://dep.debian.net/deps/dep5 +Upstream-Name: mon +Source: http://mon.buetow.org + +Files: * +Copyright: 2012 Paul Buetow <paul@buetow.org> +License: GPL-3.0+ + +Files: debian/* +Copyright: 2012 Paul Buetow <paul@buetow.org> +License: GPL-3.0+ + +License: GPL-3.0+ + 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 3 of the License, or + (at your option) any later version. + . + This package is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + . + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + . + On Debian systems, the complete text of the GNU General + Public License version 3 can be found in "/usr/share/common-licenses/GPL-3". + + diff --git a/debian/files b/debian/files new file mode 100644 index 0000000..1e9ea35 --- /dev/null +++ b/debian/files @@ -0,0 +1 @@ +mon_1.0.0_all.deb utils optional diff --git a/debian/mon.debhelper.log b/debian/mon.debhelper.log new file mode 100644 index 0000000..545a50f --- /dev/null +++ b/debian/mon.debhelper.log @@ -0,0 +1,45 @@ +dh_auto_configure +dh_auto_build +dh_auto_test +dh_prep +dh_installdirs +dh_auto_install +dh_install +dh_installdocs +dh_installchangelogs +dh_installexamples +dh_installman +dh_installcatalogs +dh_installcron +dh_installdebconf +dh_installemacsen +dh_installifupdown +dh_installinfo +dh_pysupport +dh_installinit +dh_installmenu +dh_installmime +dh_installmodules +dh_installlogcheck +dh_installlogrotate +dh_installpam +dh_installppp +dh_installudev +dh_installwm +dh_installxfonts +dh_installgsettings +dh_bugfiles +dh_ucf +dh_lintian +dh_gconf +dh_icons +dh_perl +dh_usrlocal +dh_link +dh_compress +dh_fixperms +dh_installdeb +dh_gencontrol +dh_md5sums +dh_builddeb +dh_builddeb diff --git a/debian/mon.manpages b/debian/mon.manpages new file mode 100644 index 0000000..202840a --- /dev/null +++ b/debian/mon.manpages @@ -0,0 +1 @@ +docs/mon.1 diff --git a/debian/mon.substvars b/debian/mon.substvars new file mode 100644 index 0000000..bcb0957 --- /dev/null +++ b/debian/mon.substvars @@ -0,0 +1,2 @@ +perl:Depends=perl +misc:Depends= diff --git a/debian/mon/DEBIAN/control b/debian/mon/DEBIAN/control new file mode 100644 index 0000000..35e9094 --- /dev/null +++ b/debian/mon/DEBIAN/control @@ -0,0 +1,12 @@ +Package: mon +Version: 3.0.1 +Architecture: all +Maintainer: Paul Buetow <paul@buetow.org> +Installed-Size: 126 +Depends: perl, libwww-perl, libtime-modules-perl, libconfig-json-perl, libio-socket-ssl-perl, libunix-syslog-perl, libjson-xs-perl, libterm-readline-gnu-perl +Recommends: ca-root-cert, vim +Section: utils +Priority: optional +Homepage: https://mamat-git0101.infra.server.lan/mon +Description: A simple monitoring API tool + Uses the RESTlos monitoring API to configure monitoring stuff. diff --git a/debian/mon/DEBIAN/md5sums b/debian/mon/DEBIAN/md5sums new file mode 100644 index 0000000..54cd36a --- /dev/null +++ b/debian/mon/DEBIAN/md5sums @@ -0,0 +1,21 @@ +8397dbe590d346eb3b925331eb5c2db1 usr/bin/m +8397dbe590d346eb3b925331eb5c2db1 usr/bin/mon +504f6e72ac6e115d63d3e9a1ccd1288c usr/bin/mi +e7abd63037f4be7013488c671a4716dd usr/share/doc/mon/changelog.gz +f125cc11bbc34b49bbfc518d07a96213 usr/share/doc/mon/copyright +9d4f77923a3c90cd6c5e2fe2136db9b6 usr/share/man/man1/mon.1.gz +a93997a0ddabf9ca06e602cca2134ea4 usr/share/mon/contrib/zsh/_mon.zsh +fc1844f15efdefc185d67518ae4857c2 usr/share/mon/examples/mon.conf.sample +7b124b0a3bc0bc716d3434f994fa7498 usr/share/mon/ca.pem +84722dc1495b5dba22d013eacba87ee8 usr/share/mon/lib/MON/Cache.pm +2c1750e42e80ba05c59af0b7a15f2407 usr/share/mon/lib/MON/Config.pm +752936b2d93398123c8d2238f8f9c9db usr/share/mon/lib/MON/Display.pm +442663ada73b39675e6e3a0012ad268a usr/share/mon/lib/MON/Filter.pm +330f96c524cd1c0dc012d94c7e216201 usr/share/mon/lib/MON/JSON.pm +f6dab5e42b4367a1af832cd76fc2b92b usr/share/mon/lib/MON/Options.pm +581f3d813169e433953fa761efb555fd usr/share/mon/lib/MON/Query.pm +ce6a905ad17647d4b7a3bfe268ac9b73 usr/share/mon/lib/MON/QueryBase.pm +5baa39a120e8a8d66d38e9490e93dd17 usr/share/mon/lib/MON/RESTlos.pm +6c8278360c0676c7c0f208b1d884128c usr/share/mon/lib/MON/Syslogger.pm +b62cea4e2ffd5b449f10e8b209fc151d usr/share/mon/lib/MON/Utils.pm +662f52dba3387be714becad581d0ac87 usr/share/mon/version diff --git a/debian/mon/usr/bin/m b/debian/mon/usr/bin/m new file mode 100755 index 0000000..162f71a --- /dev/null +++ b/debian/mon/usr/bin/m @@ -0,0 +1,133 @@ +#!/usr/bin/perl +# +# (c) 2013, 2014 1&1 Internet AG +# Paul C. Buetow <paul@buetow.org> + +use strict; +use warnings; +use v5.10; +use autodie; + +use Data::Dumper; +use Term::ReadLine; + +$| = 1; +my $lib; + +BEGIN { + if ( -d './lib/MON' ) { + $lib = './lib'; + + } + else { + $lib = '/usr/share/mon/lib'; + } + + unless ( exists $ENV{HTTPS_CA_FILE} ) { + if ( -f 'ca.pem' ) { + $ENV{HTTPS_CA_FILE} = 'ca.pem'; + } + elsif ( -f '/etc/ssl/certs/ca.pem' ) { + $ENV{HTTPS_CA_FILE} = '/etc/ssl/certs/ca.pem'; + } + else { + $ENV{HTTPS_CA_FILE} = '/usr/share/mon/ca.pem'; + } + } +} + +use lib $lib; + +use MON::RESTlos; +use MON::Config; +use MON::Options; +use MON::Query; +use MON::Syslogger; +use MON::Utils; +use MON::Display; + +sub main (@) { + my @args = @_; + my @opts; + + # Only interpret OPTIONS if they are at the beginning + push @opts, shift @args while @args and $args[0] =~ /^-/; + + # .. or at the end + push @opts, pop @args while @args and $args[-1] =~ /^-/; + + my $options = MON::Options->new( opts_passed => \@opts ); + my $logger = MON::Syslogger->new( options => $options ); + my $config = MON::Config->new( options => $options, logger => $logger ); + + if ( $config->{'version'} ) { + print get_version(), "\n"; + exit 0; + } + + $logger->logg( 'info', "Invoked by $ENV{USER} (params: @ARGV)" ); + + if ( $config->{interactive} ) { + my $term = Term::ReadLine->new('Monitoring API tool'); + my $prompt = '>> '; + my $out = $term->OUT || \*STDOUT; + + say $out "Welcome to the Monitoring API Tool v" . get_version(); + say $out "Press Ctrl+D to exit; Prefix cmd with ! to run via shell"; + + while ( defined( $_ = $term->readline($prompt) ) ) { + $term->addhistory($_) if /\S/; + + if (s/^!//) { + system($_); + } + else { + + my $line = $_; + + my @args = split / +/, $line; + + my $api = MON::RESTlos->new( config => $config ); + my $query = MON::Query->new( + config => $config, + api => $api, + options => $options, + args => \@args + ); + $query->parse(); + } + } + + } + else { + my $api = MON::RESTlos->new( config => $config ); + my $query = MON::Query->new( + config => $config, + api => $api, + options => $options, + args => \@args + ); + + $query->parse(); + $query->verbose("Good bye"); + + if ( $api->{had_error} != 0 ) { + + # Needed by Puppet to re-try operation the next Puppet run + if ( $config->{errfile} ne '' ) { + open my $fh, $config->{errfile} or die "$!: $config->{errfile}"; + print $fh "Exited with an error\n"; + close $fh; + } + + exit 2; + } + else { + unlink $config->{errfile} + if $config->{errfile} ne '' and -f $config->{errfile}; + exit 0; + } + } +} + +main @ARGV; diff --git a/debian/mon/usr/bin/mi b/debian/mon/usr/bin/mi new file mode 100755 index 0000000..49efcc0 --- /dev/null +++ b/debian/mon/usr/bin/mi @@ -0,0 +1,3 @@ +#!/bin/sh + +exec mon --meta --interactive $@ diff --git a/debian/mon/usr/bin/mon b/debian/mon/usr/bin/mon new file mode 100755 index 0000000..162f71a --- /dev/null +++ b/debian/mon/usr/bin/mon @@ -0,0 +1,133 @@ +#!/usr/bin/perl +# +# (c) 2013, 2014 1&1 Internet AG +# Paul C. Buetow <paul@buetow.org> + +use strict; +use warnings; +use v5.10; +use autodie; + +use Data::Dumper; +use Term::ReadLine; + +$| = 1; +my $lib; + +BEGIN { + if ( -d './lib/MON' ) { + $lib = './lib'; + + } + else { + $lib = '/usr/share/mon/lib'; + } + + unless ( exists $ENV{HTTPS_CA_FILE} ) { + if ( -f 'ca.pem' ) { + $ENV{HTTPS_CA_FILE} = 'ca.pem'; + } + elsif ( -f '/etc/ssl/certs/ca.pem' ) { + $ENV{HTTPS_CA_FILE} = '/etc/ssl/certs/ca.pem'; + } + else { + $ENV{HTTPS_CA_FILE} = '/usr/share/mon/ca.pem'; + } + } +} + +use lib $lib; + +use MON::RESTlos; +use MON::Config; +use MON::Options; +use MON::Query; +use MON::Syslogger; +use MON::Utils; +use MON::Display; + +sub main (@) { + my @args = @_; + my @opts; + + # Only interpret OPTIONS if they are at the beginning + push @opts, shift @args while @args and $args[0] =~ /^-/; + + # .. or at the end + push @opts, pop @args while @args and $args[-1] =~ /^-/; + + my $options = MON::Options->new( opts_passed => \@opts ); + my $logger = MON::Syslogger->new( options => $options ); + my $config = MON::Config->new( options => $options, logger => $logger ); + + if ( $config->{'version'} ) { + print get_version(), "\n"; + exit 0; + } + + $logger->logg( 'info', "Invoked by $ENV{USER} (params: @ARGV)" ); + + if ( $config->{interactive} ) { + my $term = Term::ReadLine->new('Monitoring API tool'); + my $prompt = '>> '; + my $out = $term->OUT || \*STDOUT; + + say $out "Welcome to the Monitoring API Tool v" . get_version(); + say $out "Press Ctrl+D to exit; Prefix cmd with ! to run via shell"; + + while ( defined( $_ = $term->readline($prompt) ) ) { + $term->addhistory($_) if /\S/; + + if (s/^!//) { + system($_); + } + else { + + my $line = $_; + + my @args = split / +/, $line; + + my $api = MON::RESTlos->new( config => $config ); + my $query = MON::Query->new( + config => $config, + api => $api, + options => $options, + args => \@args + ); + $query->parse(); + } + } + + } + else { + my $api = MON::RESTlos->new( config => $config ); + my $query = MON::Query->new( + config => $config, + api => $api, + options => $options, + args => \@args + ); + + $query->parse(); + $query->verbose("Good bye"); + + if ( $api->{had_error} != 0 ) { + + # Needed by Puppet to re-try operation the next Puppet run + if ( $config->{errfile} ne '' ) { + open my $fh, $config->{errfile} or die "$!: $config->{errfile}"; + print $fh "Exited with an error\n"; + close $fh; + } + + exit 2; + } + else { + unlink $config->{errfile} + if $config->{errfile} ne '' and -f $config->{errfile}; + exit 0; + } + } +} + +main @ARGV; diff --git a/debian/mon/usr/share/doc/mon/changelog.gz b/debian/mon/usr/share/doc/mon/changelog.gz new file mode 100644 index 0000000..89f05ae - |
