Using agent items

The web scenario-based monitoring we just set up is quite powerful, but there might be cases when a more simple approach would be enough. On the agent level, there are some interesting item keys that allow retrieving web pages and performing simple verification. An additional benefit is the ability to do that from any agent, so it is very easy to check web page availability from multiple geographically distributed locations. There are three web page-related item keys:

  • web.page.get
  • web.page.perf
  • web.page.regexp

Tip

Also keep in mind the more simple item keys such as net.tcp.service, discussed in Chapter 3, Monitoring with Zabbix Agents and Basic Protocols.

Getting the page

The most simple web page-related agent item key, web.page.get, allows us to retrieve page content. The same as scenario-based web monitoring, it does not retrieve any included content, such as images. Let's create a simple item with this key. Navigate to Configuration | Hosts, and select Web pages in the Group dropdown. Click on Items next to OpenStreetMap, and click on Create item. Fill in the following:

  • Name: OpenStreetMap main page
  • Key: web.page.get[www.openstreetmap.org,/]
  • Type of information: Text
  • New application: OSM

Tip

We are creating an agent item for our Zabbix server. This means that this web item will be checked by the local agent.

When done, click on the Add button at the bottom. In this item, we specified / as the second parameter, but that is optional—by default, root on the web server is requested. If a custom port has to be used, it can be specified as the third parameter, like this:

web.page.get[www.site.lan,/,8080]

Instead of checking the results of each of the items we are creating individually, let's create all three items first and then verify the results.

Checking page performance

Another web page-related agent item is web.page.perf. It returns the loading time of the page in seconds. While still in the item list, click on Create item, and fill in the following:

  • Name: OpenStreetMap main page load time
  • Key: web.page.perf[www.openstreetmap.org,/]
  • Type of information: Numeric (float)
  • Units: s
  • Applications: OSM

When done, click on the Add button at the bottom. We changed Type of information as this item key returns the time it took to load the page in seconds, and that value usually will have a decimal part.

Extracting content from web pages

When creating the web monitoring scenario earlier, we used the ability to extract content from a page and reuse it later. With the more simple agent monitoring, it is still possible to extract some content from a page. As a test, we could try to extract the text after OpenStreetMap is and up to the first comma. Click on Create item again, and fill in the following:

  • Name: OpenStreetMap is
  • Key: web.page.regexp[www.openstreetmap.org,,,OpenStreetMap is ([a-z ]*),,,1]
  • Type of information: Character
  • Applications: OSM

Tip

The inner square brackets contain a-z —there is a space after z.

When done, click on the Add button at the bottom.

Tip

The item key works with OpenStreetMap page contents at the time of writing this. If the web page gets redesigned, consider it an extra challenge to adapt the regular expression.

For this item, we are extracting search results from the page directly. The important parameter here is the fourth one—it is a regular expression that would be matched in the page source. In this case, we are looking for the OpenStreetMap is string and including everything after it up to the first comma in a capture group. We included the regular expression in double quotes because it contains a comma. A comma is the item key parameter separator, so it could be misinterpreted. Then, in the last parameter, we request only the contents of the first capture group to be included. By default, the whole matched string is returned. For more detail on value extraction with this method, refer to Log file monitoring in Chapter 11, Advanced Item Monitoring. We also chose Type of information to be Character—that will limit the values to 255 symbols, just in case it matches a huge string.

Tip

For this key, the fifth parameter allows us to limit the length of the returned key. If you want to extract a number and send it over SMS, limiting the length of the extracted string to 50 characters would reduce the possibility of the message being too long.

A practical application of this item would be extracting statistics from an Apache web server when using mod_status or similar functionality with other server software.

Note

None of the three web.page.* items support HTTPS, authentication, or redirects at this time.

With the items configured, let's check their returned values—head to Monitoring | Latest data, clear out the Host groups field, select OpenStreetMap in the Hosts field, and then click on Filter. Look for items in the OSM application:

Extracting content from web pages

Note

Each item requests the page separately.

The items should be returning full page contents, the time it took to load the page, and the result of our regular expression. The web.page.get item always includes headers, too. If you see empty values appearing every now and then in the web.page.get and web.page.regexp items, it probably happens because of the request timing out. While web scenarios had their own timeout setting, the agent items obey the agent timeout of 3 seconds by default. The web.page.perf item returns 0 upon a timeout.

Note

The Zabbix web.page.get item currently does not work properly with chunked transfer encoding, which is widely used. Extra data is inserted in the page contents. This was expected to be fixed in Zabbix 3.0 by using libcurl for these agent items as well, but that development was not finished. At the time of writing this, it is not known when this could be fixed.

Using these items, we could trigger when a page takes long to load or does not work at all or when a specific string cannot be found on the page—using str() and similar trigger expressions either on the whole page item or on the content extraction item.

Note

Web scenarios are executed on the Zabbix server, agent items on the agent. We will discuss the ability of running web scenarios on remote systems in Chapter 19, Using Proxies to Monitor Remote Locations.

The items we created all went to the same Zabbix agent. We can also create a host with multiple interfaces and assign items to each interface. This allows us to check a web page from multiple locations but keep the results in a single host. We still have to make the item keys unique—if needed, either use the trick with empty key parameters, extra commas in key parameters, or key aliasing, discussed in Chapter 22, Zabbix Maintenance. Note that templates can't be used in such a setup.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.145.173