📜 ⬆️ ⬇️

Zabbix + SoapUI = monitoring web services

Today, there are many applications and software systems from different developers, which we use to solve common problems. Data exchange and interaction between applications provide web services. To test their work, debugging the interaction between themselves and client applications also released a lot of tools. The most popular of them is SoapUI : it supports SOAP / WSDL, REST, HTTP (S), JDBS, JMS and has a set of tools that make testing easier and more intuitive. SoapUI acts as a test service and test client and allows you to test the integration of subsystems. More information about the tool can be found on the official website of the developer .



If a single computer and a set of applications are used to solve the task, a PC crash or a failure of one of the programs is detected quickly. But what to do when there is a lot of hardware and software in the organization? It is physically difficult and very costly to monitor and check every free minute whether everything is in order. To solve this problem, specialized software systems come to the rescue, of which you will find a lot of them on the Internet: one of them is Zabbix.

This software package is designed to track various network parameters and hardware performance. If any monitoring element fails, Zabbix will be able to notify interested persons via e-mail and sms. Read more about Zabbix can also be found on the official website of the developer .
')
Imagine the situation. The company uses many technical tools that Zabbix monitors, and various applications are not own development, but other IT companies. Part or all of these solutions are related to each other and solve one problem. To ensure timely detection of failures in this set of elements and quickly locate the problem, we need to set up web services monitoring.
What are the options?

The first option is using Zabbix functionality, configure web monitoring.


This guide is not about how to work with Zabbix, so I will briefly describe the steps.

Create a script.
Setup - Web– Create Script.



On the “Script” tab, you must fill in the “Data Item Group” and “Name” (script) fields.



Go to the tab "Steps", add a step script. Fill in the fields: step name, URL, response code.

In the "URL" enter the address of the desired web service: http: // Host: port / Service_name .

In the "Answer code" enter " 200 OK (" good "). A list of all HTTP status codes can be found here.



Next, set up a trigger on the created script.



Fill in the required fields: the name of the trigger and the expression - as shown in the figure below.



What did we get as a result? We created a web monitoring element - “Test”, which polls the page at the address specified in the script, and a trigger that will work as soon as the web service is unavailable (that is, the “Monitoring” monitoring element receives a code other than “200” ).

This will be sufficient if nothing is needed except to make sure that the web service is available. But, if you need to monitor not only accessibility, but also the correctness of the work, then this method will not work.

The second option is to “make friends” with Zabbix and SoapUI.


Immediately clarify: Zabbix-server deployed on a machine running Linux.

We presume that SoapUI is already installed on the machine where the Zabbix server is spinning. For example, let's take a certain web service Soap with a single getScore method, which, at the client's request, returns a certain data structure: sections with the names of fields and sections with data.



To understand that a web service is working correctly, you need to set criteria:
A) the method returns the correct answer;
B) the method returns the correct composition of the fields in the field section;
C) the method returns a non-empty data set (data sections are filled);
D) the number of fields in the sections of fields and data are equal;

The first thing to do is create the test itself, which we plan to check the correctness of the web service. SoapUI allows you to create test scripts to fully test web services.



As can be seen in the screenshot above, checks on criteria A and B are implemented by standard SoapUI tools. To implement checks on the criteria of B and G will have to "poshamanit" with the element SoapUI "Groovy Scripts".



def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context ); step=context.testCase.getTestStepAt(1); def holder = groovyUtils.getXmlHolder(step.name+"#Response"); holder.declareNamespace("scor","http://xml.spss.com/scoring-v2") ; holder.declareNamespace("rem","http://xml.spss.com/scoring-v2/remote") ; def columnNamesNode = holder.getDomNodes("//scor:columnNames/scor:name"); def rowValuesNode = holder.getDomNodes("//scor:rowValues"); def ValuesNode = holder.getDomNodes("//rem:getScoreResponse[1]/scor:scoreResult[1]/scor:rowValues[1]/scor:value"); int countNames = columnNamesNode.size(); int countRowValues = rowValuesNode.size(); int countValues = ValuesNode.size(); assert   countRowValues>0 : log.error("The Node with name \"rowValues\" is not found in the Response"); assert   countNames==countValues : log.error ("The count of elements of the node \"columnNames\" doesn't coincide with count of  elements  of the node \"rowValues\"!"); 

So, the test script to verify the correctness of the web service is ready. It remains to make Zabbix and SoapUI work in conjunction.

SoapUI tests can be run from the console. Why not use this opportunity?

Below is a listing script for monitoring various services.

 #!/bin/sh ##   SoapUI pathSoapUIDirectory=/usr/local/soapUI/bin/ ##    Zabbix pathZabbixDirectory=/etc/zabbix ## ,    SoapUI   - pathSoapUiProjectWithName=$pathZabbixDirectory/WebTest/"$2.xml" ##   ,      - pathParentReportDir=/var/www/zabbix/SoapReport ##   ,      - c     pathReportsDirectory=$pathParentReportDir/"$2" ##         .   ,     ,           pathReportsDirectoryForHost=$pathReportsDirectory/"$1" ##              -,         . if [ -d "$pathParentReportDir" ]; then chmod 666 "$pathParentReportDir" else mkdir "$pathParentReportDir" chmod 666 "$pathParentReportDir" fi if [ -d "$pathReportsDirectory" ]; then chmod 666 "$pathReportsDirectory" else mkdir "$pathReportsDirectory" chmod 666 "$pathReportsDirectory" fi if [ -d "$pathReportsDirectoryForHost" ]; then chmod 666 "$pathReportsDirectoryForHost" else mkdir "$pathReportsDirectoryForHost" chmod 666 "$pathReportsDirectoryForHost" fi ##   ,   SoapUI   ,    .     searchfile=$pathReportsDirectoryForHost/"alltests-fails.html" ## host:port/service_name endPoint="$3" ##   ,      ( Excel),   pathTestdataDirectory=$pathZabbixDirectory/WebTest/TestData/"$6" ##    - Excel workSpaceName="$7" ##      testSuiteName="$4" ##      testCaseName="$5" ##    ,       ,     SoapUI commandString="sh $pathSoapUIDirectory/testrunner.sh -e $endPoint -s $testSuiteName" if [ -n "$testCaseName" ] then commandString=${commandString}" -c $testCaseName" fi commandString=${commandString}" -r -j -f $pathReportsDirectoryForHost" if [ -n "$pathTestdataDirectory" ] then commandString=${commandString}" -P pathTestData=$pathTestdataDirectory -P varSpace=$workSpaceName" fi commandString=${commandString}" -I $pathSoapUiProjectWithName" ##     zabbix cd /home/zabbix $commandString > $pathReportsDirectoryForHost/"$2RunLogs.txt" ###For Debug### #errorString="### ErrorCode: 1 - error of start of the project, 2 - Error of assertions of the tests, 0 - All ok. The returned code:" #echo "$errorString "$? >> /tmp/"$2RunLogs.txt" if [ $? -ne 0 ]; then echo "ErrorOfRunProject" else if [ ! -f "$searchfile" ] then echo "FileNotFound" else if grep -w "Failure" "$searchfile" > /dev/null; then echo "TestFailure" else echo "OK" fi fi fi 

This script must be placed in the / externalscripts folder so that “Zabbix” can see it, because, by default, external scripts must be located in this folder. In our case, the “RunTestService.sh” script should be in “/ etc / zabbix / externalscripts”. You need to give the script permission to start:

 sudo chmod 755 /etc/zabbix/externalscripts/RunTestService.sh 

It remains to configure Zabbix itself to work with this script. To do this, you need to create a data item with the type "External Verification".



Since the script returns text values, it is necessary to specify “Text” in the “Type of information”.
The “key” looks like this:

 RunTestService.sh["{HOSTNAME}","ScoringProcessTests","{$SCORING.ENDPOINT}","getScoreTestSuite","getScoreTestCase"] 

Where:
"RunTestService.sh" - our script;
"{HOSTNAME}" - the name of the host on which the service is deployed to separate the reports of some services on different hosts;
“ScoringProcessTests” - the name of the SoapUI project for testing a web service;
"{$ ENDPOINT}" - the URL of the web service;
“GetScoreTestSuite” - the name of the test set of scenarios in the project SoapUI;
“GetScoreTestCase” is the name of the test script in the SoapUI project;

In order for Zabbix to inform about a detected web service failure, you need to configure a trigger.



The trigger will be triggered if the data element receives a value other than “OK”, and Zabbix displays in its interface the fact of a failure detection and notifies the interested persons by mail, sms or other means. The way of notification depends on the needs of users.

Thus, Zabbix and SoapUI each separately for free provide a huge range of functions. Individually, these products cannot solve the tasks that they have in strength in tandem. How else to implement this bundle, everyone can come up with himself.

PS: The other day I deployed Zabbix from scratch on Centos 7 OS and set up monitoring according to the algorithm described above. It turned out a number of details that I can deliver a number of problems.

1. To work correctly, you need X11
2. SoaupUIPRO 5.1.1 not higher. (Write in the LAN, if you need links))))
3. Sometimes the response of the “ErrorOfRunProject” script is returned to the zabbiks, although it works out from the console under a zabbix user. This is resolved by granting the zabbix user the right to run SoapUI under sudo for this, in / etc / sudoers, at the end of the file, add a line like this:
 zabbix ALL=(ALL) NOPASSWD: /usr/bin/java, /usr/local/SmartBear/SoapUI-Pro-5.0.0/bin/testrunner.sh, /usr/local/SmartBear/SoapUI-Pro-5.0.0/bin/soapui-pro.sh 

Source: https://habr.com/ru/post/273805/


All Articles