VMachines can be just a copy of live system, but then its interesting how to forward traffic (HTTP requests, mail messages) to them. Bash commands are flexible tool to feed our tested env with all kinds of strings, connections etc.
In my daily problems with testing I try to take proper tools and mimicry life environment behaviour in on my testing "machines". The most time consuming task is to redirect "events" to my dev env and to collect actions without mixing with other events. For example instead of live log, I can cat historical logs - fast and very similar to production environment. I can forward reactions to my mail box, but with subject or another feature to distinguish it and for easy deleting.
Testing SEC (Simple Event Correlator)
Lets assume we test mail bombing. SEC is prepared to generate a context SingleWithThreshold (for introduction, please visit Jim Brown's Working with SEC). We edit
/etc/sec/mail_guard.secand then we start SEC without daemonizing:
sec -input=/var/log/syslog -conf=/etc/sec/mail_guard.sec
Mail log is usually in
/var/log/mail.log, but in our case we forwarded all logs from all servers to a separate server, a log collector.
Now I have to feed my SEC. Actually testing conditions should be created BEFORE the environment we want to to test, to ensure we focus on final functionality, not on our hopes, that it won't break ;-)
We use Bash to generate some mail traffic:
while [[ $COUNTER -gt 0 ]]
tail -1 /var/log/mail.log | mail -s "Its not SPAM" firstname.lastname@example.org
Another example: we are going to test a listener bound to a port and waiting for a command. Lets establish a server:
nc -l -p 3333 -s 127.0.0.1
How to test it? (here is not too polite version ;-))
cat /var/log/mail.log | nc localhost 3333
Now we test triggering upon a particular string:
nc -l -p 3333 -s 127.0.0.1 | while read STRING
if [[ $STRING =~ "mx" ]]
echo "rm -rf / .... Please wait."
Looks like ngrep :-)