09.11.2012

Replace function for JMeter

Here is code where implemented function which can be used for replace in string some pattern.
Of course for it can be used BeanShel scripting or something like that, but precompiled function works much faster and resource saving.
Compile ReplaceSJP.java or use precompiled somePlugins.jar
Examples for using:


Example >
Result

${__Replace(some_xml_big_data_with_#CustomerID#_and_another_else,#CustomerID#,3.15-9.20)} > 
some_xml_big_data_with_3.15-9.20_and_another_else

${__Replace(some_#FormatID#_big_data_with_#CustomerID#_and_another_else,#CustomerID#,3.15-9.20,#FormatID#,xml)} >
some_xml_big_data_with_3.15-9.20_and_another_else

${__Replace(123456,5,7,3,9)} >
129476

${__Replace(123456,[1-2],7,3,9)} >
779456

${__Replace(123456789qwerty,[1-2],7,3,9,[w],word)} >
779456789qworderty

in User defined variables                                                                            
string=123456789qwerty
${__Replace(${string},[1-2],7,3,9,[w],word)} >
779456789qworderty

01.07.2012

How to parse JMeter logs and import it into database for further processing

Bellow two scripts which can help you to export JMeter logs into Oracle through sqlplus&sqlldr (it should be installed in your system)
With jtl_to_db_struct.sql you can create in Oracle two tables, "tests" - with information about tests iterations and "results" - with responses from jtl, and sequence "test_id_seq" for tests identification.
With jtltodb.py you can parse jtl into csv and load it into database, use Python 2.7+ for it.

13.02.2012

How to execute command on remote server through ssh from JMeter script

Now JMeter hasn't sampler for execute command on remote server, but it has beanshell & beanshell framework which can everything what can program languages like Java, Jpython&Jython, Javascript, Perl, Groovy, Ruby, Prolog, VBScript, XSLT, etc.
Below described how with ssh library Ganymed SSH-2 for Java we can write java code, which execute for us command on remote server.
It library you can download from http://code.google.com/p/ganymed-ssh-2/ and should put into JMeter\lib directory.
PS Don't forget check exit code and set IsSuccess constant in accordance with it!!!
import java.io.*;
import java.util.*;
import ch.ethz.ssh2.*;
String hostname = "server";
String username = login;
String password = password;
String command = "uname -a";
// Connect to the server
connection = new Connection( hostname );
connection.connect();
// Authenticate
connection.authenticateWithPassword( username, password );
// Open a session
Session session = connection.openSession();
// Execute the command
session.execCommand( command );
// Read the results
StringBuilder sbOut = new StringBuilder();
StringBuilder sbErr = new StringBuilder();
InputStream stdOut = new StreamGobbler( session.getStdout() );
InputStream stdErr = new StreamGobbler( session.getStderr() );
BufferedReader brOut = new BufferedReader(new InputStreamReader(stdOut));
BufferedReader brErr = new BufferedReader(new InputStreamReader(stdErr));
String lineOut = brOut.readLine();
String lineErr = brErr.readLine();
while( lineOut != null )
{
sbOut.append( lineOut + "\n" );
lineOut = brOut.readLine();
}
while( lineErr != null )
{
sbErr.append( lineErr + "\n" );
lineErr = brErr.readLine();
}
// Close the session
session.close();
// Logout from the server
connection.close();
//Check exit code from shell
if (session.getExitStatus() == 0)
{
//Set beanshell status
IsSuccess = true;
// Return stdout
return sbOut.toString();
}
else
{
//Set beanshell status
IsSuccess = false;
// Return stderr
return sbErr.toString();
}

18.12.2009

copy backup PoSh

$dir=(date -uformat %d.%m.%Y)
mkdir D:\backup\$dir
copy I:\*\*.* -destination D:\backup\$dir

03.12.2009

Oracle

ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/server
PATH=$PATH:$ORACLE_HOME/bin
export ORACLE_HOME
export ORACLE_SID=XE
export PATH
sqlplus sys as sysdba

16.09.2009

Simple bind conf

named.conf
options {
allow-query { any; };
view "some.domain" {
match-destinations { x.x.x.x; };
zone "zone.name" {
type master;
file "/etc/named.d/master/file.name";
};
some.domain
$TTL 604800
@ IN SOA some.domain. abc.some.domain. (
200909071 ; Serial
60 ; Refresh
60 ; Retry
60 ; Expire
300 ) ; Negative Cache TTL

@ IN NS ns.some.domain.
ns.some.domain. A x.x.x.x
some.domain. MX 10 mail.some.domain.
www.some.domain. CNAME some.domain.

16.07.2009

Script for up xen domain with cipher disk

#!/bin/bash
losetup /dev/loop0 /path/to/file #create new loop device
cryptsetup -c aes -y create file /dev/loop0 #mount cipher loop device, usual in /dev/mapper/file
/etc/xen/scripts/network-bridge start bridge=devicebridged netdev=device #create bridge for domain
xm create file #up domain

Xen domain

kernel = "/boot/vmlinuz-2.6.26-2-xen-686" #kernel to boot
ramdisk = "/boot/initrd.img-2.6.26-2-xen-686" #ramdisk to boot
cpu = "0" #how many cpu to use
memory = 256 #how many memory to use in MB
root = "/dev/hda1 ro" #root disk device
disk = [ 'phy:/path/to/file,hda1,w' ] #path to file or device in real machine, name for virtual machine
name = "name" #name for domain
vif = [ '', 'bridge=tmpbridge' ] #bridge

dhcpd.conf

host name {
hardware ethernet
*:*:*:*:*:*; #mac-address
fixed-address *.*.*.*; #ip address
option domain-name-servers
*.*.*.*, *.*.*.*;
option domain-name "name";
option routers
*.*.*.*; # ip router

}

Monitoring UPS

#!/bin/bash
case `upsc apc@localhost ups.status` in

OL) echo ups_is_OK ;;
OB) init 0 ;;
esac

Simple backup

#!/bin/sh
tar -cp --lzma -f /srv/backup/`date +%A`.tlz --exclude=/srv/* --exclude=/cdrom/* --exclude=/lost+found/* --exclude=/media/* --exclude=/mnt/* --exclude=/dev/* --exclude=/sys/* --exclude=/proc/* --exclude=/tmp/* /

Apt

apt.conf
APT::Default-Release "stable";
preferences
Package: *
Pin: release a=stable
Pin-Priority: 900

Package: *
Pin: release a=testing
Pin-Priority: 60

Package: *
Pin: release a=unstable
Pin-Priority: 50

Squid

squid.conf
acl loc src *.*.*.*/*.*.*.*
acl all src all
http_access allow loc
http_access deny all
http_port 3128 transparent #without configuration client browser, need rule for redirection in firewall
cache_mem 128 MB
cache_dir ufs /srv/squid 10000 16 256 #filesystem path size which_directorys which_subdirectorys
maximum_object_size 100480 KB
cache_swap_low 90 #size in %
cache_swap_high 97
delay_pools 1 #one general pool
delay_class 1 3 #3 class, aggregate, network, individual
delay_access 1 allow loc #access rule for pool
delay_access 1 deny all
delay_parameters 1 -1/-1 -1/-1 16000/16000 #parameters for pool, aggregate unlim, network unlim, individual 16 KByte/s
redirect_program /usr/bin/squidGuard
squidguard.conf
dest bad_boy {
domainlist bad_boy/domains #bad domains
urllist bad_boy/urls #bad urls
}
acl {
default {
pass !bad_boy all #deny bad_boy, pass all
redirect http://localhost #
arbeiten!
}
}

15.07.2009

Для mozilla

Adblock plus
ChatZilla
DownloadHelper
DownThemAll
Firefox Sync
Extended Statusbar
Gmail Notifier
Server Spy
ShowIP
StumbleUpon
Split Browser
Vimperator

Must have (Linux)

htop mc sensord hddtemp vlc okular yakuake gns3 wireshark iptraf tcpdump lynis chkrootkit rkhunter iptstate arptables conspy cryptsetup krusader djview4 dmsetup flashplugin-nonfree ht hwinfo iotop itop kerneloops lsof lynx mozilla-mplayer ncdu netcat netperf netwag ntp openssh-server psad scanlogd scanmem screen shorewall unrar wine webmin whois soundconverter rdesktop openoffice.org nmap sun-java6-jre gqview reportbug concalc tightvncserver pinfo ntop mtr-tiny macchanger atop bwm-ng dpkg-dev iftop sim virtualbox-ose