Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 1cb0a3be

Přidáno uživatelem Ondřej Fibich před téměř 11 roky(ů)

Adds files from the main FreenetIS repository and enhances DEB package.

Zobrazit rozdíly:

.gitignore
/deb/deb_packages/
LICENSE
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
{one line to give the program's name and a brief idea of what it does.}
Copyright (C) {year} {name of author}
Monitoring tool for FreenetIS.
Copyright (C) 2013 FreenetIS
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
......
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
{project} Copyright (C) {year} {fullname}
freenetis-monitoring Copyright (C) 2013 Ondrej Fibich
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
README.md
freenetis-monitoring
FreenetIS Monitoring
====================
Devices which are obtain from the FreenetIS are monitored using fping tool and their states are send back to the FreenetIS. The communication is made using wget tool.
Devices which are obtain from the FreenetIS are monitored using fping tool and their states are send back to the FreenetIS. The communication is made using wget tool.
For more informations see <http://wiki.freenetis.org/index.php/Instalace#Bal.C3.ADk_freenetis-monitoring>.
Changelog
---------
Changelog in debian format is available [here](deb/changelog).
deb/changelog
freenetis-monitoring (0.9.5) stable; urgency=hight
* Fixes dependency issue for killall (#565)
-- Ondrej Fibich <ondrej.fibich@gmail.com> Sat, 06 Apr 2013 12:59:28 +0200
freenetis-monitoring (0.9.4) stable; urgency=low
* Fixes dependencies
-- Ondrej Fibich <ondrej.fibich@gmail.com> Mon, 13 Aug 2012 11:24:14 +0200
freenetis-monitoring (0.9.3) stable; urgency=low
* Remove using of sudo in init script
-- Ondrej Fibich <ondrej.fibich@gmail.com> Tue, 07 Aug 2012 09:40:34 +0200
freenetis-monitoring (0.9.2) stable; urgency=low
* Repair header on debian squeeze
-- Ondrej Fibich <ondrej.fibich@gmail.com> Tue, 07 Aug 2012 09:40:34 +0200
freenetis-monitoring (0.9.1) stable; urgency=low
* Repair of pre-configuration of package
-- Ondrej Fibich <ondrej.fibich@gmail.com> Mon, 06 Aug 2012 12:56:53 +0200
freenetis-monitoring (0.9.0) stable; urgency=low
* First release
-- Ondrej Fibich <ondrej.fibich@gmail.com> Fri, 03 Aug 2012 11:15:48 +0200
deb/conffiles
/etc/freenetis/freenetis-monitoring.conf
/etc/init.d/freenetis-monitoring
deb/config
#!/bin/sh
set -e
. /usr/share/debconf/confmodule
CONFIGFILE=/etc/freenetis/freenetis-monitoring.conf
CONFIGFILE_FN=/etc/freenetis/freenetis.conf
# pre-fill if not pre-filled already
db_get freenetis-monitoring/hack_reload
if [ "$RET" = true ] && [ -e $CONFIGFILE ]; then
. $CONFIGFILE || true
db_set freenetis-monitoring/path_freenetis "$PATH_FN"
fi
# h@ck for not reloading variables from config file (enabled again by postinst)
db_set freenetis-monitoring/hack_reload false
# Ask questions.
db_input critical freenetis-monitoring/path_freenetis || true
db_go || true
deb/control
Priority: optional
Section: web
Pre-Depends: debconf (>= 0.5) | debconf-2.0
Depends: coreutils (>= 6.10-6), grep (>= 2.5.3), procps, fping, wget (>= 1.11-4.1), psmisc
Architecture: all
Maintainer: Ondrej Fibich <ondrej.fibich@gmail.com>
Homepage: http://www.freenetis.org
Description: FreenetIS monitoring - monitoring tool for FreenetIS
Devices which are obtain from the FreenetIS are monitored using fping tool
and their states are send back to the FreenetIS. The communication is made
using wget tool.
Description-cs.UTF-8: FreenetIS monitoring - monitorovací nástroj pro FreenetIS
Zařízení, které jsou získány z FreenetISu, jsou monitorovány nástrojem fping
a jejich stavy jsou zasílány zpět do FreenetISu. Komunikace probíhá pomocí
nástroje wget.
deb/debianization.sh
#!/bin/sh
################################################################################
# Script for debianization of FreenetIS redirection and QoS package
# (c) Ondrej Fibich, 2012
#
# Takes two arguments (version of package - FreenetIS and debian version).
#
################################################################################
if [ $# -ne 2 ]; then
echo "Wrong arg count.. Terminating"
exit 1
fi
NAME=freenetis-monitoring
VERSION=$1
DEBIAN=$2
# create dirs ##################################################################
mkdir -p deb_packages/tmp
cd deb_packages/tmp
mkdir -m 755 DEBIAN
mkdir -m 755 etc
mkdir -m 755 etc/init.d
mkdir -m 755 etc/freenetis
mkdir -m 755 usr
mkdir -m 755 usr/sbin
mkdir -m 755 usr/share
mkdir -m 755 usr/share/doc
mkdir -m 755 usr/share/doc/${NAME}
# doc ##########################################################################
# change log
cat ../../changelog >> usr/share/doc/${NAME}/changelog
# debian change log is same
cp usr/share/doc/${NAME}/changelog usr/share/doc/${NAME}/changelog.Debian
# copyright
echo "This package was debianized by Ondrej Fibich <ondrej.fibich@gmail.com> on `date -R`" >> usr/share/doc/${NAME}/copyright
echo "It was downloaded from <http://freenetis.org/>\n" >> usr/share/doc/${NAME}/copyright
echo "Copyright:\n" >> usr/share/doc/${NAME}/copyright
echo " Copyright 2010-2013 Ondřej Fibich <ondrej.fibich@gmail.com>" >> usr/share/doc/${NAME}/copyright
echo " Copyright 2018-2013 Michal Kliment <kliment@freenetis.org>" >> usr/share/doc/${NAME}/copyright
echo "\nLicense:\n" >> usr/share/doc/${NAME}/copyright
echo " This program is free software: you can redistribute it and/or modify" >> usr/share/doc/${NAME}/copyright
echo " it under the terms of the GNU General Public License as published by" >> usr/share/doc/${NAME}/copyright
echo " the Free Software Foundation, either version 3 of the License, or" >> usr/share/doc/${NAME}/copyright
echo " (at your option) any later version." >> usr/share/doc/${NAME}/copyright
echo "" >> usr/share/doc/${NAME}/copyright
echo " This program is distributed in the hope that it will be useful," >> usr/share/doc/${NAME}/copyright
echo " but WITHOUT ANY WARRANTY; without even the implied warranty of" >> usr/share/doc/${NAME}/copyright
echo " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the" >> usr/share/doc/${NAME}/copyright
echo " GNU General Public License for more details." >> usr/share/doc/${NAME}/copyright
echo "" >> usr/share/doc/${NAME}/copyright
echo "On Debian systems, the complete text of the GNU General" >> usr/share/doc/${NAME}/copyright
echo "Public License can be found in \`/usr/share/common-licenses/GPL-3'.\n" >> usr/share/doc/${NAME}/copyright
echo -n "The Debian packaging is (C) `date +%Y`, Ondrej Fibich <ondrej.fibich@gmail.com> and" >> usr/share/doc/${NAME}/copyright
echo " it is licensed under the GPL, see above.\n" >> usr/share/doc/${NAME}/copyright
# man pages
# rights
chmod 644 usr/share/doc/${NAME}/changelog usr/share/doc/${NAME}/changelog.Debian \
usr/share/doc/${NAME}/copyright
# compress doc
gzip --best usr/share/doc/${NAME}/changelog
gzip --best usr/share/doc/${NAME}/changelog.Debian
# copy content of package ######################################################
cp ../../../freenetis-monitoring.init.sh etc/init.d/${NAME}
cp ../../../freenetis-monitord.sh usr/sbin/freenetis-monitord
cp ../../../freenetis-monitoring.conf etc/freenetis/
# count size
SIZE=`du -s etc usr | cut -f1 | paste -sd+ | bc`
# calculate checksum ###########################################################
find * -type f ! -regex '^DEBIAN/.*' -exec md5sum {} \; >> DEBIAN/md5sums
# create info files ############################################################
# create package info
echo "Package: ${NAME}" >> DEBIAN/control
echo "Version: ${VERSION}-${DEBIAN}" >> DEBIAN/control
echo "Installed-Size: ${SIZE}" >> DEBIAN/control
cat ../../control >> DEBIAN/control
# scripts ######################################################################
cp -a -f ../../postinst DEBIAN/postinst
cp -a -f ../../prerm DEBIAN/prerm
cp -a -f ../../postrm DEBIAN/postrm
cp -a -f ../../templates DEBIAN/templates
cp -a -f ../../config DEBIAN/config
cp -a -f ../../conffiles DEBIAN/conffiles
chmod 644 DEBIAN/control DEBIAN/md5sums DEBIAN/templates DEBIAN/conffiles \
etc/freenetis/freenetis-monitoring.conf
chmod 755 DEBIAN/prerm DEBIAN/postinst DEBIAN/postrm DEBIAN/config \
etc/init.d/${NAME} usr/sbin/freenetis-monitord
chmod +x DEBIAN/postinst DEBIAN/postrm DEBIAN/prerm DEBIAN/config
# create deb ###################################################################
# change owner of files to root (security)
cd ..
fakeroot chown -hR root:root *
# make package
fakeroot dpkg-deb -b tmp ${NAME}_${VERSION}+${DEBIAN}.deb
# clean-up mess ################################################################
# clean
rm -rf tmp
deb/postinst
#!/bin/bash
# FreenetIS-monitoring DEB: actions after installing of package
set -e
. /usr/share/debconf/confmodule
NAME=freenetis-monitoring
CONFIGFILE=/etc/freenetis/freenetis-monitoring.conf
# Quit if config file is missing.
if [ ! -e $CONFIGFILE ]; then
echo "$CONFIGFILE not founded!"
exit 1
fi
url_regex='(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]'
# Substitute in the values from the debconf db.
# There are obvious optimizations possible here.
# The cp before the sed ensures we do not mess up
# the config file’s ownership and permissions.
db_get freenetis-monitoring/path_freenetis
PATH_FN="$RET"
# check path
if [ -z "$PATH_FN" ]; then
echo "Empty path to FreenetIS instance, configuration failed!"
exit 3
fi
cp -a -f $CONFIGFILE $CONFIGFILE.tmp
# If the admin deleted or commented some variables but then set
# them via debconf, (re-)add them to the conffile.
test -z "$PATH_FN" || grep -Eq '^ *PATH_FN=' $CONFIGFILE || echo "PATH_FN=" >> $CONFIGFILE
PATH_FN_ESCAPED="${PATH_FN//\//\\/}"
sed -e "s/^ *PATH_FN=.*/PATH_FN=\"$PATH_FN_ESCAPED\"/" < $CONFIGFILE > $CONFIGFILE.tmp
mv -f $CONFIGFILE.tmp $CONFIGFILE
# Make post install things
# 1) Startup at boot
# set on fire after boot
update-rc.d freenetis-monitoring defaults
exit 0
deb/postrm
#!/bin/sh
# FreenetIS DEB: actions after uninstalling of package
set -e
. /usr/share/debconf/confmodule
NAME=freenetis-monitoring
CONFIGFILE=/etc/freenetis/freenetis-monitoring.conf
# disable startup from update-rc.d
set +e
update-rc.d -f freenetis-monitoring remove
set -e
# remove all configuration if purge
if [ "$1" = purge ]; then
# remove defconf values
if [ -e /usr/share/debconf/confmodule ]; then
db_purge
fi
# remove config files
rm -rf $CONFIGFILE
# remove dir if empty
[ "$(ls -A /etc/freenetis)" ] || rm -rf /etc/freenetis
fi
exit 0
deb/prerm
#!/bin/sh
# FreenetIS DEB: actions before uninstalling of package
set -e
NAME=freenetis-monitoring
CONFIGFILE=/etc/freenetis/freenetis-monitoring.conf
# stop daemon
if [ -x /usr/sbin/invoke-rc.d ]; then
invoke-rc.d $NAME stop 3>/dev/null || true
else
/etc/init.d/$NAME stop 3>/dev/null || true
fi
exit 0
deb/templates
Template: freenetis-monitoring/path_freenetis
Type: string
Default: http://localhost/freenetis
Description: FreenetIS URL:
Base path to running FreenetIS instance (e.g. http://freenet.org/is)
Description-cs.UTF-8: FreenetIS URL:
Cesta ke kořenu běžící instalace FreenetISu (např. http://freenet.org/is)
Template: freenetis-monitoring/hack_reload
Type: boolean
Default: true
Description: Hack for propper working of package configuration?
freenetis-monitord.sh
#!/bin/bash
################################################################################
# #
# This script serves for monitoring from IS FreeNetIS #
# #
# author Kliment Michal 2012 #
# email kliment@freenetis.org #
# #
# name freenetis-monitord.sh #
# version 0.9.3 #
# #
################################################################################
#Load variables from config file
CONFIG=/etc/freenetis/freenetis-monitoring.conf
# temporary file with list of IP addresses to monitor
HOSTS_INPUT=`mktemp`
# temporary file with result to send
HOSTS_OUTPUT=`mktemp`
FPING="/usr/bin/fping"
# -------------------------------------------------------------------------
# Copyright (c) 2005 nixCraft project <http://cyberciti.biz/fb/>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------
# Get OS name
function get_ip()
{
OS=`uname`
IO="" # store IP
case $OS in
Linux) IP=`ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'`;;
FreeBSD|OpenBSD) IP=`ifconfig | grep -E 'inet.[0-9]' | grep -v '127.0.0.1' | awk '{ print $2}'` ;;
SunOS) IP=`ifconfig -a | grep inet | grep -v '127.0.0.1' | awk '{ print $2} '` ;;
*) IP="Unknown";;
esac
echo -n "$IP"
}
# Load variables
if [ -e $CONFIG ]; then
. $CONFIG
else
echo "Config file is missing at path $CONFIG."
echo "Terminating..."
exit 0
fi
# try to create log file if not exists
if [ ! -e "$LOG_FILE" ] ; then
set +e
touch "$LOG_FILE"
set -e
fi
# disable logging if log cannot be written
if [ ! -w "$LOG_FILE" ]; then
echo "Cannot write to $LOG_FILE file => disabling logging"
LOG_FILE=/dev/null
fi
# endless loop
while true;
do
echo "Downloading list of IP addresses to monitor..."
# get ip addresses from FreenetIS
http_code=`wget --no-check-certificate --server-response -q "$HOSTS_INPUT_URL$1" -O "$HOSTS_INPUT" 2>&1 | awk '/^ HTTP/{print $2}'`
## access forbidden
if [ "$http_code" = "403" ]; then
# write to log if not already written
if [ -z "$ERROR_WRITEN" ]; then
echo -n "`date -R` " 1>&2
echo -n "Wrong configuration of FreenetIS - access from monitoring server not allowed. " 1>&2
echo -n "Set IP address of monnitoring server to \"" 1>&2
get_ip 1>&2
echo "\" in FreenetIS settings." 1>&2
ERROR_WRITEN=1
fi
echo "Wrong configuration of FreenetIS - access from monitoring server not allowed."
echo "Set IP address of monnitoring server to \"" $(get_ip) "\" in FreenetIS settings."
echo ""
continue
fi
# use fping to get ip addresses states
$FPING -e -f "$HOSTS_INPUT" 2>>$LOG_FILE | while read host
do
# ip address
ip=`echo $host | awk '{print $1}'`
# state of host (alive or unreachable)
state=`echo $host | awk '{print $3}'`
# latency of host (only for alive state)
lat=`echo $host | awk '{print $4}' | sed 's/(//'`
# do not add ampersand to beginning of file with result
if [ -s "$HOSTS_OUTPUT" ];
then
echo -n "&" >> "$HOSTS_OUTPUT";
fi
# add variables to file with result
echo "ip[]=$ip&state[]=$state&lat[]=$lat" >> "$HOSTS_OUTPUT"
done
# remove temporary file with IP addresses to monitor
rm -f "$HOSTS_INPUT"
echo "Sending result data back to FreenetIS..."
echo ""
# send file with result back to FreenetIS
wget -qO- --no-check-certificate --post-file="$HOSTS_OUTPUT" "$HOSTS_OUTPUT_URL"
# remove temporary file with result
rm -f "$HOSTS_OUTPUT"
done
freenetis-monitoring.conf
################################################################################
# #
# This script serves for IS FreeNetIS (monitoring) #
# #
# author Kliment Michal 2011 #
# email kliment@freenetis.org #
# #
# name freenetis-monitoring.conf #
# version 0.9.3 #
# #
################################################################################
################################################################################
# G E N E R A L S E T T I N G S #
################################################################################
# Base PATH_FN to running FreenetIS instance
PATH_FN=http://localhost/freenetis
# Log file, change to /dev/null to disable logging
LOG_FILE=/var/log/freenetis-monitoring.log
# 0 = Monitoring will be run in 1 process for all priorities
# 1..N = Monitoring will be run in 1 process for each priority in interval <0;MAX_PRIORITY>
MAX_PRIORITY=0
# URL with IP addresses to monitor [DO NOT CHANGE THIS VARIABLE!]
HOSTS_INPUT_URL=$PATH_FN"/index.php/en/web_interface/monitoring_hosts/"
# URL to which we send result [DO NOT CHANGE THIS VARIABLE!]
HOSTS_OUTPUT_URL=$PATH_FN"/index.php/en/web_interface/monitoring_states/"
freenetis-monitoring.init.sh
#! /bin/bash
### BEGIN INIT INFO
# Provides: freenetis-monitoring
# Required-Start: $remote_fs
# Required-Stop: $remote_fs
# Should-Start: $network $syslog
# Should-Stop: $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start and stop freenetis monitoring daemon
# Description: FreeNetIS monitoring script.
### END INIT INFO
################################################################################
# #
# This script serves for monitoring from IS FreeNetIS #
# #
# Author Kliment Michal 2012 #
# Email kliment@freenetis.org #
# #
# Name freenetis-monitoring.init.sh #
# Version 0.9.3 #
# #
################################################################################
# Load variables from config file
CONFIG=/etc/freenetis/freenetis-monitoring.conf
# Name of monitoring daemon
MONITORD="freenetis-monitord"
# Path to monitoring daemon (without name)
MONITORD_PATH="/usr/sbin/"
# Load variables
if [ -e $CONFIG ]; then
. $CONFIG || true
else
echo "Config file is missing at path $CONFIG."
echo "Terminating..."
exit 0
fi
# try to create log file if not exists
if [ ! -e "$LOG_FILE" ] ; then
set +e
touch "$LOG_FILE"
set -e
fi
# disable logging if log cannot be written
if [ ! -w "$LOG_FILE" ]; then
echo "Cannot write to $LOG_FILE file => disabling logging"
LOG_FILE=/dev/null
fi
start_monitor()
{
# test if daemon is already started
if [ `ps aux | grep $MONITORD | grep -v grep | wc -l` -gt 0 ];
then
echo "Already started."
return 0
fi
echo -n "Starting FreenetIS monitor daemon: "
# max priority is set
if [ $MAX_PRIORITY -gt 0 ];
then
# create process for all priority from interval <0;MAX_PRIORITY>
for i in `seq 0 $MAX_PRIORITY`;
do
nohup $MONITORD_PATH$MONITORD $i 1>/dev/null 2>>$LOG_FILE &
done
else
# create one process for all priorities
nohup $MONITORD_PATH$MONITORD 1>/dev/null 2>>$LOG_FILE &
fi
# test if daemon is started
if [ `ps aux | grep $MONITORD | grep -v grep | wc -l` -gt 0 ];
then
echo "OK"
else
echo "FAILED!";
fi
}
stop_monitor()
{
# test if daemon is already stopped
if [ `ps aux | grep $MONITORD | grep -v grep | wc -l` -eq 0 ];
then
echo "Not running."
return 0
fi
echo -n "Stopping FreenetIS monitor daemon: "
# kill all processes
killall -q $MONITORD
# test if daemon is stopped
if [ `ps aux | grep $MONITORD | grep -v grep | wc -l` -eq 0 ];
then
echo "OK"
else
echo "FAILED!";
fi
}
status_monitor()
{
echo -n "FreenetIS monitor daemon is "
# test if daemon is already started
if [ `ps aux | grep $MONITORD | grep -v grep | wc -l` -gt 0 ];
then
echo "running."
else
echo "not running.";
fi
}
usage_monitor()
{
echo "usage: `echo $0` (start|stop|restart|status)"
}
case "$1" in
start)
start_monitor
exit 0
;;
stop)
stop_monitor
exit 0
;;
restart|reload|force-reload) # reload is same thing as reload
stop_monitor
start_monitor
exit 0
;;
status)
status_monitor
exit 0
;;
*)
usage_monitor
exit 0
;;
esac
exit 0

Také k dispozici: Unified diff