2008-01-02 Sancho lerena <slerena@gmail.com>

* openWRT/*: Added code for new ASYNC agent for OpenWRT/Arduino
        agent, this would be the new SYNC/ASYNC agent for Pandora FMS 2.0.
        This is first development version, DO NOT TEST YET. It has several
        code specific for OpenWRT enviroment.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@686 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
slerena 2008-01-02 17:28:09 +00:00
parent aba6bd86d9
commit 3176799f8b
12 changed files with 1453 additions and 0 deletions

View File

@ -1,3 +1,10 @@
2008-01-02 Sancho lerena <slerena@gmail.com>
* openWRT/*: Added code for new ASYNC agent for OpenWRT/Arduino
agent, this would be the new SYNC/ASYNC agent for Pandora FMS 2.0.
This is first development version, DO NOT TEST YET. It has several
code specific for OpenWRT enviroment.
2007-09-14 Sancho Lerena <slerena@gmail.com>
* Deleted a lot of old stuff (licenses, readmes, etc). Put on agent root dir

View File

@ -0,0 +1,2 @@
Sancho Lerena <slerena@gmail.com>
Raul Mateos <raulofpandora@gmail.com>

View File

@ -0,0 +1,340 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey 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>
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
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, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision 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.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.

View File

@ -0,0 +1,8 @@
#!/bin/sh
# Pandora FMS preparation script for OpenWRT
# (c) Sancho Lerena, Jorge Loza, 2007-2008
mkdir /tmp/.ssh
cp /opt/pandora/known_host /tmp/.ssh
sh /opt/pandora/contrib/pandora_agent_daemon start

View File

@ -0,0 +1,66 @@
#!/bin/sh
# Init script for Pandora FMS agent
# Generic GNU/Linux version
# Sancho Lerena, <slerena@gmail.com>
# v1.3
### BEGIN INIT INFO
# Provides: pandora_agent
# Required-Start: $network
# Required-Stop: $network
# Default-Start: S 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start/stop pandora-agent daemon
### END INIT INFO
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin
PANDORA_PATH=/opt/pandora
DAEMON=/opt/pandora/pandora_agent
PIDFILE=/opt/pandora/pandora_agent.pid
LOGFILE=/opt/pandora/pandora_agent.log
if [ ! -f $DAEMON ]
then
echo "Pandora FMS Agent not found at $DAEMON, please check setup"
exit
fi
case "$1" in
start)
if [ -f $PIDFILE ]
then
PID_BA=`cat $PIDFILE`
if [ ! -z "`ps -w | awk '{ print $2 }' | grep $PID_BA`" ]
then
echo "Pandora FMS Agent is currently running on this machine with PID $PID_BA"
echo "Cannot launch again. Aborting."
exit
fi
fi
$DAEMON $PANDORA_PATH 2> $LOGFILE & MYPID=$!
echo $MYPID > $PIDFILE
echo "Pandora FMS Agent is now running with PID $MYPID"
;;
stop)
if [ -f $PIDFILE ]
then
echo "Stopping Pandora Agent."
PID_2=`cat $PIDFILE`
if [ ! -z "`ps | grep -v grep | grep 'pandora_agent'`" ]
then
kill -9 $PID_2
fi
rm -f $PIDFILE
else
echo "Pandora FMS Agent is not running, cannot stop it. Aborting now..."
fi
;;
force-reload|restart)
$0 stop
$0 start
;;
*)
echo "Uso: /etc/init.d/pandora_agent_daemon {start|stop|restart|force-reload}"
exit 1
esac

View File

@ -0,0 +1,153 @@
#!/bin/bash
# **********************************************************************
# Pandora FMS Agent - Generic Host Agent Installer
# GNU/Linux version
# (c) 2007 Sancho Lerena <slerena@gmail.com>
# Please see http://pandora.sourceforge.net
# This code is licensed under GPL 2.0 license.
# **********************************************************************
PI_VERSION=1.0
PANDORA_BIN=/usr/bin/pandora_agent
PANDORA_HOME=/usr/share/pandora
PANDORA_TEMP=/var/spool/pandora
PANDORA_CFG=/etc/pandora
PANDORA_LOG=/var/log/pandora_agent.log
PANDORA_STARTUP=/etc/init.d/pandora_agent_daemon
FORCE=0
LOG_TIMESTAMP=`date +"%Y/%m/%d %H:%M:%S"`
MODE=$1
if [ ! -f "pandora_agent" ]
then
echo " "
echo "You need to place pandora_agent file on main distribution directory before install"
echo " "
exit 1
fi
uninstall () {
echo "Removing Pandora FMS Agent..."
rm -Rf $PANDORA_BIN
rm -Rf $PANDORA_TEMP
rm -Rf $PANDORA_CFG
rm -Rf $PANDORA_STARTUP
rm -Rf $PANDORA_HOME
rm -Rf $PANDORA_LOG
echo "Done"
}
install () {
if [ -f $PANDORA_HOME ] && [ "$FORCE" = "0" ]
then
echo "Seems that default dir already exists. Please use --force to"
echo "force installer to install on $PANDORA_HOME"
exit
else
echo "Checking default dir $PANDORA_HOME..."
fi
if [ -f $PANDORA_BIN ] && [ "$FORCE" = "0" ]
then
echo "Seems that $PANDORA_BIN already exists. Please use --force to"
echo "force installer to reinstall overwriting it"
exit
else
echo "Checking Pandora FMS Agent on $PANDORA_BIN...."
fi
# Create directories
echo "Creating Pandora FMS Agent home directory at $PANDORA_HOME ..."
mkdir $PANDORA_HOME
mkdir $PANDORA_TEMP
mkdir $PANDORA_TEMP/data_out
mkdir $PANDORA_CFG
# Create logfile
if [ ! -z "`touch $PANDORA_LOG`" ]
then
echo "Seems to be a problem generating logfile ($PANDORA_LOG) please check it";
else
echo "Creating logfile at $PANDORA_LOG..."
fi
echo "$LOG_TIMESTAMP Pandora FMS installer has created this file at startup" > $PANDORA_LOG
# Copying agent and securing it
echo "Copying Pandora FMS Agent to $PANDORA_BIN..."
cp pandora_agent $PANDORA_BIN
chmod 700 $PANDORA_BIN
echo "Copying Pandora FMS Agent contrib dir to $PANDORA_HOME/contrib..."
cp -R contrib $PANDORA_HOME
echo "Copying Pandora FMS Agent configuration file to $PANDORA_HOME/pandora_agent.conf..."
cp pandora_agent.conf $PANDORA_HOME
chmod 600 $PANDORA_HOME/pandora_agent.conf
echo "Copying Pandora FMS Agent user configuration file to $PANDORA_HOME/pandora_user.conf..."
cp pandora_user.conf $PANDORA_HOME
chmod 700 $PANDORA_HOME/pandora_user.conf
echo "Linking Pandora FMS Agent configuration to $PANDORA_CFG/pandora_agent.conf..."
ln -s $PANDORA_HOME/pandora_agent.conf $PANDORA_CFG
echo "Linking Pandora FMS Agent user configuration to $PANDORA_CFG/pandora_user.conf..."
ln -s $PANDORA_HOME/pandora_user.conf $PANDORA_CFG
echo "Setting secure permissions and ownership for all Pandora FMS Agent files..."
chown -R root $PANDORA_HOME
chmod -R 700 $PANDORA_HOME/util
chmod -R 600 $PANDORA_TEMP/data_out
chmod -R 700 $PANDORA_HOME/contrib
chmod 640 $PANDORA_LOG
chgrp 3 $PANDORA_LOG
echo "Linking start-up daemon script at $PANDORA_STARTUP";
ln -s $PANDORA_HOME/contrib/pandora_agent_daemon $PANDORA_STARTUP
chown -R root $PANDORA_BIN
echo "Done."
echo " "
echo "You have your startup script ready at $PANDORA_STARTUP"
echo "First you need to copy your public SSH keys ($HOME/.ssh/id_dsa)"
echo "under /home/pandora/.ssh/authorized_keys on your Pandora FMS Server host"
echo "You also need to setup your $PANDORA_CFG/pandora_agent.conf config file"
echo " "
}
help () {
echo " --force-install To force installation if already installed on system "
echo " --install To install Pandora FMS Agent on this system"
echo " --uninstall To uninstall and remove Pandora FMS Agent on this System"
echo " "
}
# Script banner at start
echo " "
echo "Pandora FMS Agent Installer $PI_VERSION (c) 2007 Sancho Lerena"
echo "This program is licensed under GPL2 Terms. http://pandora.sourceforge.net"
echo " "
case "$MODE" in
'--force-install')
FORCE=1
install
exit
;;
'--install')
install
exit
;;
'--uninstall')
uninstall
exit
;;
*)
help
esac

View File

@ -0,0 +1,318 @@
#!/bin/sh
# **********************************************************************
# Pandora FMS Generic Host Agent
# GNU/Linux version
# (c) 2003-2007 Sancho Lerena <slerena@gmail.com>
# with the help of many people. Please see http://pandora.sourceforge.net
# This code is licensed under GPL 2.0 license.
# **********************************************************************
AGENT_VERSION=1.3-dev
AGENT_BUILD=070421
if [ -z "$1" ]
then
echo " "
echo "Fatal error: I need an argument to Pandora FMS Agent config directory"
echo " "
echo " example: pandora_agent /etc/pandora "
echo " "
exit -1
else
PANDORA_HOME=$1
fi
if [ ! -f $PANDORA_HOME/pandora_agent.conf ]
then
echo " "
echo "FATAL ERROR: Cannot load $PANDORA_HOME/pandora_agent.conf"
echo " "
exit -1
fi
# Init internal variables
CONTADOR=0
EXECUTE=1
MODULE_END=0
TIMESTAMP=`date +"%Y/%m/%d %H:%M:%S"`
IFS="
"
# Default values
CHECKSUM_MODE=1
DEBUG_MODE=0
SERVER_PORT=22
INTERVAL=300
TRANSFER_MODE=ssh
if [ -z "`echo $LANG | grep '\.'`" ]
then
ENCODING="iso-8859-1"
else
ENCODING=`echo $LANG | cut -f 2 -d "."`
fi
NOMBRE_HOST="linksys"
OS_NAME=`uname -s`
PANDORA_LOGFILE=/var/log/pandora_agent.log
TEMP=/tmp
# Read config file
for a in `cat $PANDORA_HOME/pandora_agent.conf | grep -v -e "^#" | grep -v -e "^module" `
do
a=`echo $a | tr -s " " " "`
# Get general configuration parameters from config file
if [ ! -z "`echo $a | grep -e '^logfile'`" ]
then
PANDORA_LOGFILE=`echo $a | awk '{ print $2 }' `
echo "$TIMESTAMP - [SETUP] - Pandora Logfile is $PANDORA_LOGFILE" >> $PANDORA_LOGFILE
fi
if [ ! -z "`echo $a | grep -e '^server_ip'`" ]
then
SERVER_IP=`echo $a | awk '{ print $2 }' `
echo "$TIMESTAMP - [SETUP] - Server IP Address is $SERVER_IP" >> $PANDORA_LOGFILE
fi
if [ ! -z "`echo $a | grep -e '^server_path'`" ]
then
SERVER_PATH=`echo $a | awk '{ print $2 }' `
echo "$TIMESTAMP - [SETUP] - Server Path is $SERVER_PATH" >> $PANDORA_LOGFILE
fi
if [ ! -z "`echo $a | grep -e '^temporal'`" ]
then
TEMP=`echo $a | awk '{ print $2 }' `
echo "$TIMESTAMP - [SETUP] - Temporal Path is $TEMP" >> $PANDORA_LOGFILE
fi
if [ ! -z "`echo $a | grep -e '^interval'`" ]
then
INTERVAL=`echo $a | awk '{ print $2 }' `
echo "$TIMESTAMP - [SETUP] - Interval is $INTERVAL seconds" >> $PANDORA_LOGFILE
fi
if [ ! -z "`echo $a | grep -e '^agent_name'`" ]
then
NOMBRE_HOST=`echo $a | awk '{ print $2 }' `
echo "$TIMESTAMP - [SETUP] - Agent name is $NOMBRE_HOST " >> $PANDORA_LOGFILE
fi
if [ ! -z "`echo $a | grep -e '^debug'`" ]
then
DEBUG_MODE=`echo $a | awk '{ print $2 }' `
echo "$TIMESTAMP - [SETUP] - Debug mode is $DEBUG_MODE " >> $PANDORA_LOGFILE
fi
if [ ! -z "`echo $a | grep -e '^checksum'`" ]
then
CHECKSUM_MODE=`echo $a | awk '{ print $2 }' `
echo "$TIMESTAMP - [SETUP] - Checksum is $CHECKSUM_MODE " >> $PANDORA_LOGFILE
fi
# Contribution of daggett
if [ ! -z "`echo $a | grep -e '^server_port'`" ]
then
SERVER_PORT=`echo $a | awk '{ print $2 }' `
echo "$TIMESTAMP - [SETUP] - Server Port is $SERVER_PORT" >> $PANDORA_LOGFILE
fi
# Contribution of daggett
if [ ! -z "`echo $a | grep -e '^encoding'`" ]
then
ENCODING=`echo $a | awk '{ print $2 }' `
echo "$TIMESTAMP - [SETUP] - Encoding is $ENCODING" >> $PANDORA_LOGFILE
fi
if [ ! -z "`echo $a | grep -e '^transfer_mode'`" ]
then
TRANSFER_MODE=`echo $a | awk '{ print $2 }' `
echo "$TIMESTAMP - [SETUP] - Transfer Mode is $TRANSFER_MODE" >> $PANDORA_LOGFILE
fi
done
# Script banner at start
echo "Pandora FMS Agent / Linksys $AGENT_VERSION (c) Sancho Lerena, Jorge Loza 2007"
echo "This program is licensed under GPL2 Terms. http://pandora.sf.net"
echo "Running in $NOMBRE_HOST at $TIMESTAMP"
echo " "
# Make some checks
if [ "$TRANSFER_MODE" = "ftp" ]
then
if [ ! -f $HOME/.netrc ]
then
echo "(EE) Transfer mode is FTP but there is no usable .netrc file. Aborting."
exit
fi
fi
if [ "$DEBUG_MODE" = "1" ]
then
echo "(**) Warning: Running in DEBUG mode"
fi
# MAIN Program loop begin
while [ "1" = "1" ]
do
# Deleted debug / error info on each run to avoid giant logs
rm -Rf $PANDORA_LOGFILE.err 2> /dev/null
# Date and time, SERIAL is number of seconds since 1/1/1970, for every packet.
TIMESTAMP=`date +"%Y/%m/%d %H:%M:%S"`
SERIAL=`date +"%s"`
# File names
DATA=$TEMP/$NOMBRE_HOST.$SERIAL.data
DATA2=$TEMP/$NOMBRE_HOST.$SERIAL.data_temp
CHECKSUM=$TEMP/$NOMBRE_HOST.$SERIAL.checksum
PANDORA_FILES="$TEMP/$NOMBRE_HOST.$SERIAL.*"
# Makes data packet
echo "<?xml version=\"1.0\" encoding=\"$ENCODING\"?> " > $DATA
echo "<agent_data os_name='$OS_NAME' os_version='$OS_VERSION' interval='$INTERVAL' version='$AGENT_VERSION' timestamp='$TIMESTAMP' agent_name='$NOMBRE_HOST'>" >> $DATA
for a in `cat $PANDORA_HOME/pandora_agent.conf | grep -v -e "^#" | grep -e "^module" `
do
a=`echo $a | tr -s " " " "`
if [ ! -z "`echo $a | grep -e '^module_exec'`" ]
then
if [ $EXECUTE -eq 0 ]
then
execution=`echo $a | cut -c 13- `
res=`eval $execution`
if [ -z "$flux_string" ]
then
res=`eval expr $res 2> $PANDORA_LOGFILE.err`
fi
echo "<data><![CDATA[$res]]></data>" >> $DATA2
fi
fi
if [ ! -z "`echo $a | grep -e '^module_name'`" ]
then
name=`echo $a | cut -c 13- `
echo "<name><![CDATA[$name]]></name>" >> $DATA2
fi
if [ ! -z "`echo $a | grep -e '^module_begin'`" ]
then
echo "<module>" >> $DATA2
EXECUTE=0
fi
if [ ! -z "`echo $a | grep -e '^module_max' `" ]
then
max=`echo $a | awk '{ print $2 }' `
echo "<max><![CDATA[$max]]></max>" >> $DATA2
fi
if [ ! -z "`echo $a | grep -e '^module_min'`" ]
then
min=`echo $a | awk '{ print $2 }' `
echo "<min><![CDATA[$min]]></min>" >> $DATA2
fi
if [ ! -z "`echo $a | grep -e '^module_description'`" ]
then
desc=`echo $a | cut -c 20- `
echo "<description><![CDATA[$desc]]></description>" >> $DATA2
fi
if [ ! -z "`echo $a | grep -e '^module_end'`" ]
then
echo "</module>" >> $DATA2
MODULE_END=1
else
MODULE_END=0
fi
if [ ! -z "`echo $a | grep -e '^module_type'`" ]
then
mtype=`echo $a | awk '{ print $2 }' `
if [ ! -z "`echo $mtype | grep 'generic_data_string'`" ]
then
flux_string=1
else
flux_string=0
unset flux_string
fi
echo "<type><![CDATA[$mtype]]></type>" >> $DATA2
fi
if [ ! -z "`echo $a | grep '^module_interval'`" ]
then
# Determine if execution is to be done
MODULEINTERVAL=`echo $a | awk '{ print $2 }'`
EXECUTE=`expr \( $CONTADOR + 1 \) % $MODULEINTERVAL`
fi
# If module ends, and execute for this module is enabled
# then write
if [ $MODULE_END -eq 1 ]
then
if [ $EXECUTE -eq 0 ]
then
cat $DATA2 >> $DATA
fi
rm -Rf $DATA2 > /dev/null 2> /dev/null
fi
done
# Count number of agent runs
CONTADOR=`expr $CONTADOR + 1`
# Keep a limit of 100 for overflow reasons
if [ $CONTADOR -eq 100 ]
then
CONTADOR=0
fi
# Call for user-defined script for data adquisition
if [ -f "$PANDORA_HOME/pandora_user.conf" ]
then
/bin/sh $PANDORA_HOME/pandora_user.conf >> $DATA
fi
# Checking MD5
if [ "$CHECKSUM_MODE" = "1" ]
then
# Calculate Checksum and prepare MD5 file
CHECKSUM_DATA=`md5sum $DATA`
echo $CHECKSUM_DATA > $CHECKSUM
else
CHECKSUM_DATA="No valid checksum"
echo $CHECKSUM_DATA > $CHECKSUM
fi
# Finish data packet
echo "</agent_data>" >> $DATA
echo "" >> $DATA
# Replace & chars in XML (should not to be any) to avoid syntax problems
sed "s/&/&amp;/g" $DATA > $TEMP/finalxml.tmp
rm -f $DATA
mv $TEMP/finalxml.tmp $DATA
if [ "$DEBUG_MODE" = "1" ]
then
echo "$TIMESTAMP - Finish writing XML $DATA" >> $PANDORA_LOGFILE
echo "(**) Data file is at $DATA - Exiting now"
echo " "
exit 0
fi
# Send packets to server and detele it
if [ "$TRANSFER_MODE" = "ssh" ]
then
scp -i /opt/pandora/ssh $PANDORA_FILES pandora@$SERVER_IP:$SERVER_PATH > /dev/null 2> $PANDORA_LOGFILE.err
fi
if [ "$TRANSFER_MODE" = "ftp" ]
then
ftp SERVER_IP > /dev/null 2> $PANDORA_LOGFILE.err
fi
if [ "$TRANSFER_MODE" = "local" ]
then
cp $PANDORA_FILES $SERVER_PATH > /dev/null 2> $PANDORA_LOGFILE.err
fi
# Delete data
rm -f $PANDORA_FILES 2> $PANDORA_LOGFILE.err
# Go to bed :-)
sleep $INTERVAL
done
# This runs forever!

View File

@ -0,0 +1,63 @@
# Base config file for Pandora FMS agents
# Version 1.2
# Licensed under GPL license v2,
# please visit http://pandora.sourceforge.net
# General Parameters
# ==================
server_ip 192.168.50.1
server_path /var/spool/pandora/data_in
temporal /tmp
logfile /opt/pandora/pandora_agent.log
# Interval in seconds, 300 by default
interval 30
# Debug mode only generate XML, and stop after first execution,
# and does not copy XML to server.
debug 0
# By default is activated
checksum 0
# By default, agent takes machine name
agent_name arduinoasus
# By default agent try to take default encoding defined in host.
# encoding iso-8859-15
# By default is 22 (for ssh)
#server_port 22
# ftp, ssh or local
transfer_mode ssh
# Module Definition
# =================
# System information
module_begin
module_name temperatura
module_type generic_data
module_interval 1
module_exec sh /opt/pandora/pandora_serialread AT
module_description temperatura
module_end
module_begin
module_name humedad
module_type generic_data
module_exec sh /opt/pandora/pandora_serialread AH
module_description humedad
module_end
module_begin
module_async D8
module_type generic_proc
module_name puerta
module_exec sh /opt/pandora/pandora_serialread D8
module_description puerta
module_end

View File

@ -0,0 +1,379 @@
#!/bin/sh
# **********************************************************************
# Pandora FMS - Asyncronous version for OpenWRT / Arduino integration
# (c) 2004-2008 Sancho Lerena <slerena@gmail.com>
# (c) 2007 Jorge Loza
# Please see Pandora FMS official home at http://pandora.sourceforge.net
# This code is licensed under GPL 2.0 licence
# **********************************************************************
AGENT_VERSION=2.0-dev
AGENT_BUILD=080102
if [ -z "$1" ]
then
echo " "
echo "Fatal error: I need an argument to Pandora FMS Agent config directory"
echo " "
echo " example: pandora_agent /opt/pandora "
echo " "
exit -1
else
PANDORA_HOME=$1
fi
if [ ! -f $PANDORA_HOME/pandora_agent.conf ]
then
echo " "
echo "FATAL ERROR: Cannot load $PANDORA_HOME/pandora_agent.conf"
echo " "
exit -1
fi
# Init internal variables
CONTADOR=0
EXECUTE=1
MODULE_END=0
TIMESTAMP=`date +"%Y/%m/%d %H:%M:%S"`
IFS="
"
# Default values
CHECKSUM_MODE=1
DEBUG_MODE=0
SERVER_PORT=22
INTERVAL=300
TRANSFER_MODE=ssh
if [ -z "`echo $LANG | grep '\.'`" ]
then
ENCODING="iso-8859-1"
else
ENCODING=`echo $LANG | cut -f 2 -d "."`
fi
NOMBRE_HOST="linksys"
OS_NAME=`uname -s`
PANDORA_LOGFILE=/var/log/pandora_agent.log
TEMP=/tmp
# Read config file
for a in `cat $PANDORA_HOME/pandora_agent.conf | grep -v -e "^#" | grep -v -e "^module" `
do
a=`echo $a | tr -s " " " "`
# Get general configuration parameters from config file
if [ ! -z "`echo $a | grep -e '^logfile'`" ]
then
PANDORA_LOGFILE=`echo $a | awk '{ print $2 }' `
echo "$TIMESTAMP - [SETUP] - Pandora Logfile is $PANDORA_LOGFILE" >> $PANDORA_LOGFILE
fi
if [ ! -z "`echo $a | grep -e '^server_ip'`" ]
then
SERVER_IP=`echo $a | awk '{ print $2 }' `
echo "$TIMESTAMP - [SETUP] - Server IP Address is $SERVER_IP" >> $PANDORA_LOGFILE
fi
if [ ! -z "`echo $a | grep -e '^server_path'`" ]
then
SERVER_PATH=`echo $a | awk '{ print $2 }' `
echo "$TIMESTAMP - [SETUP] - Server Path is $SERVER_PATH" >> $PANDORA_LOGFILE
fi
if [ ! -z "`echo $a | grep -e '^temporal'`" ]
then
TEMP=`echo $a | awk '{ print $2 }' `
echo "$TIMESTAMP - [SETUP] - Temporal Path is $TEMP" >> $PANDORA_LOGFILE
fi
if [ ! -z "`echo $a | grep -e '^interval'`" ]
then
INTERVAL=`echo $a | awk '{ print $2 }' `
echo "$TIMESTAMP - [SETUP] - Interval is $INTERVAL seconds" >> $PANDORA_LOGFILE
fi
if [ ! -z "`echo $a | grep -e '^agent_name'`" ]
then
NOMBRE_HOST=`echo $a | awk '{ print $2 }' `
echo "$TIMESTAMP - [SETUP] - Agent name is $NOMBRE_HOST " >> $PANDORA_LOGFILE
fi
if [ ! -z "`echo $a | grep -e '^debug'`" ]
then
DEBUG_MODE=`echo $a | awk '{ print $2 }' `
echo "$TIMESTAMP - [SETUP] - Debug mode is $DEBUG_MODE " >> $PANDORA_LOGFILE
fi
if [ ! -z "`echo $a | grep -e '^checksum'`" ]
then
CHECKSUM_MODE=`echo $a | awk '{ print $2 }' `
echo "$TIMESTAMP - [SETUP] - Checksum is $CHECKSUM_MODE " >> $PANDORA_LOGFILE
fi
# Contribution of daggett
if [ ! -z "`echo $a | grep -e '^server_port'`" ]
then
SERVER_PORT=`echo $a | awk '{ print $2 }' `
echo "$TIMESTAMP - [SETUP] - Server Port is $SERVER_PORT" >> $PANDORA_LOGFILE
fi
# Contribution of daggett
if [ ! -z "`echo $a | grep -e '^encoding'`" ]
then
ENCODING=`echo $a | awk '{ print $2 }' `
echo "$TIMESTAMP - [SETUP] - Encoding is $ENCODING" >> $PANDORA_LOGFILE
fi
if [ ! -z "`echo $a | grep -e '^transfer_mode'`" ]
then
TRANSFER_MODE=`echo $a | awk '{ print $2 }' `
echo "$TIMESTAMP - [SETUP] - Transfer Mode is $TRANSFER_MODE" >> $PANDORA_LOGFILE
fi
done
# Script banner at start
echo "Pandora FMS Agent / OpenWRT $AGENT_VERSION (c) Sancho Lerena, Jorge Loza 2007-2008"
echo "This program is licensed under GPL2 Terms. http://pandora.sf.net"
echo " "
# Make some checks
if [ "$TRANSFER_MODE" = "ftp" ]
then
if [ ! -f $HOME/.netrc ]
then
echo "(EE) Transfer mode is FTP but there is no usable .netrc file. Aborting."
exit
fi
fi
if [ "$DEBUG_MODE" = "1" ]
then
echo "(**) Warning: Running in DEBUG mode"
fi
# MAIN Program loop begin
DATE_START=`date +%s`
SYNC_DATA="`grep "^module_async" $PANDORA_HOME/pandora_agent.conf | wc -l`"
if [ $SYNC_DATA -gt 0 ]
then
while [ 1 ]
do
GETSYNC_DATA=`$PANDORA_HOME/pandora_getsync`
if [ "$GETSYNC_DATA" != "0" ]
then
pandora_datarun 1 "$GETSYNC_DATA"
fi
DATE_CURRENT=`date +%s`
DATE_DIFF=$(($DATE_CURRENT - $DATE_START))
if [ $DATE_DIFF -gt $INTERVAL ]
then
pandora_datarun 0 "N/A"
fi
done
else
while [ 1 ]
do
pandora_datarun 0 "N/A"
sleep $INTERVAL
done
fi
pandora_datarun () {
# Chunkmode 1 for Async, 0 for Sync
CHUNKMODE=$1
SYNCDATA=$2
# PREPARE XML DATA FILE BEGIN
# Deleted debug / error info on each run to avoid giant logs
rm -Rf $PANDORA_LOGFILE.err 2> /dev/null
# Date and time, SERIAL is number of seconds since 1/1/1970, for every packet.
TIMESTAMP=`date +"%Y/%m/%d %H:%M:%S"`
SERIAL=`date +"%s"`
# File names
DATA=$TEMP/$NOMBRE_HOST.$SERIAL.data
DATA2=$TEMP/$NOMBRE_HOST.$SERIAL.data_temp
CHECKSUM=$TEMP/$NOMBRE_HOST.$SERIAL.checksum
PANDORA_FILES="$TEMP/$NOMBRE_HOST.$SERIAL.*"
# Makes data packet
echo "<?xml version=\"1.0\" encoding=\"$ENCODING\"?> " > $DATA
echo "<agent_data os_name='$OS_NAME' os_version='$OS_VERSION' interval='$INTERVAL' version='$AGENT_VERSION' timestamp='$TIMESTAMP' agent_name='$NOMBRE_HOST'>" >> $DATA
pandora_async_chunk "$PANDORA_HOME/pandora_agent.conf" "$DATA2" "$DATA"
for a in `cat $PANDORA_HOME/pandora_agent.conf | grep -v -e "^#" | grep -e "^module" `
do
a=`echo $a | tr -s " " " "`
DIGITALGATE=0
if [ ! -z "`echo $a | grep -e '^module_exec'`" ]
then
if [ $EXECUTE -eq 0 ]
then
execution=`echo $a | cut -c 13- `
res=`eval $execution`
if [ -z "$flux_string" ]
then
res=`eval expr $res 2> $PANDORA_LOGFILE.err`
fi
echo "<data><![CDATA[$res]]></data>" >> $DATA2
fi
fi
if [ ! -z "`echo $a | grep -e '^module_async'`" ]
then
if [ $CHUNKMODE -eq 1 ]
then
DIGITALGATE=`echo $a | cut -c 14- `
if [ -z "`echo $SYNCDATA | grep \"$DIGITALGATE\"`" ]
then
EXECUTE=1
echo "Avoiding execution for DIGITALGATE $DIGITALGATE"
fi
fi
fi
if [ ! -z "`echo $a | grep -e '^module_name'`" ]
then
name=`echo $a | cut -c 13- `
echo "<name><![CDATA[$name]]></name>" >> $DATA2
fi
if [ ! -z "`echo $a | grep -e '^module_begin'`" ]
then
echo "<module>" >> $DATA2
EXECUTE=0
fi
if [ ! -z "`echo $a | grep -e '^module_max' `" ]
then
max=`echo $a | awk '{ print $2 }' `
echo "<max><![CDATA[$max]]></max>" >> $DATA2
fi
if [ ! -z "`echo $a | grep -e '^module_min'`" ]
then
min=`echo $a | awk '{ print $2 }' `
echo "<min><![CDATA[$min]]></min>" >> $DATA2
fi
if [ ! -z "`echo $a | grep -e '^module_description'`" ]
then
desc=`echo $a | cut -c 20- `
echo "<description><![CDATA[$desc]]></description>" >> $DATA2
fi
if [ ! -z "`echo $a | grep -e '^module_end'`" ]
then
echo "</module>" >> $DATA2
MODULE_END=1
else
MODULE_END=0
fi
if [ ! -z "`echo $a | grep -e '^module_type'`" ]
then
mtype=`echo $a | awk '{ print $2 }' `
if [ ! -z "`echo $mtype | grep 'generic_data_string'`" ]
then
flux_string=1
else
flux_string=0
unset flux_string
fi
echo "<type><![CDATA[$mtype]]></type>" >> $DATA2
fi
if [ ! -z "`echo $a | grep '^module_interval'`" ]
then
# Determine if execution is to be done
MODULEINTERVAL=`echo $a | awk '{ print $2 }'`
EXECUTE=`expr \( $CONTADOR + 1 \) % $MODULEINTERVAL`
fi
# If module ends, and execute for this module is enabled
# then write
if [ $MODULE_END -eq 1 ]
then
if [ $CHUNKMODE -eq 1 ]
then
if [ $DIGITALGATE -eq 0 ]
then
EXECUTE=1
fi
fi
if [ $EXECUTE -eq 0 ]
then
cat $DATA2 >> $DATA
fi
rm -Rf $DATA2 > /dev/null 2> /dev/null
# If this is SYNC mode, for each finished module
# we should check for pending ASYNC modules
# (if defined and any pending to read)
if [ $CHUNKMODE -eq 0 ] && [ $SYNC_DATA -gt 0 ]
then
GETSYNC_DATA=`$PANDORA_HOME/pandora_getsync`
if [ "$GETSYNC_DATA" != "0" ]
then
pandora_datarun 1 "$GETSYNC_DATA"
fi
fi
fi
done
# Ony for SYNC mode
if [ $CHUNKMODE -eq 0 ]
then
# Count number of agent runs
CONTADOR=`expr $CONTADOR + 1`
# Keep a limit of 100 for overflow reasons
if [ $CONTADOR -eq 100 ]
then
CONTADOR=0
fi
# Call for user-defined script for data adquisition
if [ -f "$PANDORA_HOME/pandora_user.conf" ]
then
/bin/sh $PANDORA_HOME/pandora_user.conf >> $DATA
fi
# Checking MD5
if [ "$CHECKSUM_MODE" = "1" ]
then
# Calculate Checksum and prepare MD5 file
CHECKSUM_DATA=`md5sum $DATA`
echo $CHECKSUM_DATA > $CHECKSUM
else
CHECKSUM_DATA="No valid checksum"
echo $CHECKSUM_DATA > $CHECKSUM
fi
fi
# Finish data packet
echo "</agent_data>" >> $DATA
echo "" >> $DATA
# Replace & chars in XML (should not to be any) to avoid syntax problems
sed "s/&/&amp;/g" $DATA > $TEMP/finalxml.tmp
rm -f $DATA
mv $TEMP/finalxml.tmp $DATA
if [ "$DEBUG_MODE" = "1" ]
then
echo "$TIMESTAMP - Finish writing XML $DATA" >> $PANDORA_LOGFILE
echo "(**) Data file is at $DATA - Exiting now"
echo " "
exit 0
fi
# Send packets to server and detele it
if [ "$TRANSFER_MODE" = "ssh" ]
then
scp -i /opt/pandora/ssh $PANDORA_FILES pandora@$SERVER_IP:$SERVER_PATH > /dev/null 2> $PANDORA_LOGFILE.err
fi
if [ "$TRANSFER_MODE" = "ftp" ]
then
ftp SERVER_IP > /dev/null 2> $PANDORA_LOGFILE.err
fi
if [ "$TRANSFER_MODE" = "local" ]
then
cp $PANDORA_FILES $SERVER_PATH > /dev/null 2> $PANDORA_LOGFILE.err
fi
# Delete data
rm -f $PANDORA_FILES 2> $PANDORA_LOGFILE.err
}

View File

@ -0,0 +1,17 @@
#!/bin/sh
# (c) Sancho Lerena 2008
# Pandora FMS GetSync sample for OpenWRT/Arduino Pandora FMS Agent
# pandora_sync should return a single line with Pandora FMS async module id
# separated with spaces. All ID's returned has "async" data pending to read
# the way to get this data is left to user. In this sample is resolved
# by an Arduino code that returns Digital signals with new async data by
# using code DD
# This returns D9 if D9 gate needs to be readed due an asyncronous incoming signal
# Could return D1 D5 D9 if gates D1, D5 and D9 needs to be readed
# Could return 0 if no received signal since last time readed
PANDORA_HOME=/opt/pandora
$PANDORA_HOME/pandora_serialread DD

View File

@ -0,0 +1,25 @@
#!/bin/sh
# (c) Jorge Loza, Sancho Lerena 2007-2008
# Licensed under GPL2 Terms
# Pandora FMS - http://pandora.sf.net
TMPFILE=/tmp/pandora_async.tmp
SERIALPORT=/dev/usb/tts/0
variable=0
rm $TMPFILE 2> /dev/null
# Fork and let a process reading from serialport
cat < $SERIALPORT > $TMPFILE &
# Send gate read request to SERIALPORT
echo $1 > $SERIALPORT
until test -s $TMPFILE || test $variable -ge 200
do
variable=$(($variable + 1))
done
sleep 1
cat $TMPFILE | head -1
kill -0 $! && kill $!

View File

@ -0,0 +1,75 @@
# Pandora User-Defined adquisition script
# This code is under GPL licence
# This is the default user script file
# If you're using this is because default config doest fit all your needs
# You can use the following variables
#
# All STDOUT output will be written in final XML file sent to Pandora Server.
#
# Please refer documentatation for more example and a more depth usage instructions
#
# ================================
# Check for WEBPage content change
# ================================
#MYMD5=`echo -e "GET / HTTP/1.0\n\n\n" | nc -w 30 www.artica.es 80 | grep -v "Date:" | md5sum | awk '{ print $1 }'`
#VALIDMD5=e85c0b9018a22c1086c8e0179cd224b1
#if [ "$MYMD5" != "$VALIDMD5" ]
#then
# MD5SUM=0
#else
# MD5SUM=1
#fi
#echo "<module>"
#echo "<name>www.artica.es_WEBContenct</name>"
#echo "<type>generic_proc</type>"
#echo "<data>$MD5SUM</data>"
#echo "</module>"
# MODULE END ========================
# ================================
# Check for DNS Entry change
# ================================
#HOSTNAME=arcadia.genterara.com
#MAXHOPS=1
#MAXHOPS2=`expr $MAXHOPS + 1`
#SALIDA=`traceroute -n $HOSTNAME -w 5 -m $MAXHOPS2 2> /dev/null | awk '{ print $1 }' | tail -1`
# if SALIDA != MAXHOPS, error (more than MAXHOPS hop, if this is our local IP, no more than MAXHOPS hop its needed
#if [ "$SALIDA" == "$MAXHOPS" ]
#then
# DNS_STATUS=1
#else
# DNS_STATUS=0
#fi
#echo "<module>"
#echo "<name>DNS_CHECK</name>"
#echo "<type>generic_proc</type>"
#echo "<data>$DNS_STATUS</data>"
#echo "</module>"
# MODULE END ========================
# ================================
# Check for DNS Entry change
# on local interface ppp0
# ================================
# PLC_DNS=`dig @194.179.1.101 plc.genterara.com A +short | tail -1 `
# PLC_LOCAL=`ifconfig ppp0 | head -2 | tail -1 | tr -s ":" " " | awk ' { print $3 } '`
# if [ "$PLC_DNS" == "$PLC_LOCAL" ]
# then
# PLC_STATUS=1
# else
# PLC_STATUS=0
# fi
#
# echo "<module>"
# echo "<name>PLC_DNS_CHECK</name>"
# echo "<type>generic_proc</type>"
# echo "<data>$PLC_STATUS</data>"
# echo "</module>"
# MODULE END ========================