
# Travis CI by HTTP

## Overview

The template to monitor Travis CI by Zabbix that work without any external scripts.
Most of the metrics are collected in one go, thanks to Zabbix bulk data collection.

## Requirements

Zabbix version: 7.0 and higher.

## Tested versions

This template has been tested on:
- Travis CI API V3 2021 

## Configuration

> Zabbix should be configured according to the instructions in the [Templates out of the box](https://www.zabbix.com/documentation/7.0/manual/config/templates_out_of_the_box) section.

## Setup

You must set {$TRAVIS.API.TOKEN} and {$TRAVIS.API.URL} macros.
{$TRAVIS.API.TOKEN} is a Travis API authentication token located in User -> Settings -> API authentication.
{$TRAVIS.API.URL} could be in 2 different variations:
 - for a private project : api.travis-ci.com
 - for an enterprise projects: api.example.com (where you replace example.com with the domain Travis CI is running on)

### Macros used

|Name|Description|Default|
|----|-----------|-------|
|{$TRAVIS.API.TOKEN}|
Travis API Token
||
|{$TRAVIS.API.URL}|
Travis API URL
|`api.travis-ci.com`|
|{$TRAVIS.BUILDS.SUCCESS.PERCENT}|
Percent of successful builds in the repo (for trigger expression)
|`80`|

### Items

|Name|Description|Type|Key and additional info|
|----|-----------|----|-----------------------|
|Get repos|
Getting repos using Travis API.
|HTTP agent|travis.get_repos|
|Get builds|
Getting builds using Travis API.
|HTTP agent|travis.get_builds|
|Get jobs|
Getting jobs using Travis API.
|HTTP agent|travis.get_jobs|
|Get health|
Getting home JSON using Travis API.
|HTTP agent|travis.get_health
**Preprocessing**

- 
Check for not supported value: `any error`

⛔️Custom on fail: Set value to: `0`

- 
JavaScript: `The text is too long. Please see the template.`

|
|Jobs passed|
Total count of passed jobs in all repos.
|Dependent item|travis.jobs.total
**Preprocessing**

- 
JSON Path: `$.jobs.length()`

|
|Jobs active|
Active jobs in all repos.
|Dependent item|travis.jobs.active
**Preprocessing**

- 
JSON Path: `$.jobs[?(@.state == "started")].length()`

⛔️Custom on fail: Set value to: `0`

|
|Jobs in queue|
Jobs in queue in all repos.
|Dependent item|travis.jobs.queue
**Preprocessing**

- 
JSON Path: `$.jobs[?(@.state == "received")].length()`

⛔️Custom on fail: Set value to: `0`

|
|Builds|
Total count of builds in all repos.
|Dependent item|travis.builds.total
**Preprocessing**

- 
JSON Path: `$.builds.length()`

|
|Builds duration|
Sum of all builds durations in all repos.
|Dependent item|travis.builds.duration
**Preprocessing**

- 
JSON Path: `$..duration.sum()`

⛔️Custom on fail: Discard value

|

### Triggers

|Name|Description|Expression|Severity|Dependencies and additional info|
|----|-----------|----------|--------|--------------------------------|
|Travis CI: Service is unavailable|
Travis API is unavailable. Please check if the correct macros are set.
|`last(/Travis CI by HTTP/travis.get_health)=0`|High|**Manual close**: Yes|
|Travis CI: Failed to fetch home page|
Zabbix has not received any data for items for the last 30 minutes.
|`nodata(/Travis CI by HTTP/travis.get_health,30m)=1`|Warning|**Manual close**: Yes|

### LLD rule Repos metrics discovery

|Name|Description|Type|Key and additional info|
|----|-----------|----|-----------------------|
|Repos metrics discovery|
Metrics for Repos statistics.
|Dependent item|travis.repos.discovery
**Preprocessing**

- 
JavaScript: `The text is too long. Please see the template.`

- 
Discard unchanged with heartbeat: `1h`

|

### Item prototypes for Repos metrics discovery

|Name|Description|Type|Key and additional info|
|----|-----------|----|-----------------------|
|Repo [{#SLUG}]: Get builds|
Getting builds of {#SLUG} using Travis API.
|HTTP agent|travis.repo.get_builds[{#SLUG}]|
|Repo [{#SLUG}]: Get caches|
Getting caches of {#SLUG} using Travis API.
|HTTP agent|travis.repo.get_caches[{#SLUG}]|
|Repo [{#SLUG}]: Cache files|
Count of cache files in {#SLUG} repo.
|Dependent item|travis.repo.caches.files[{#SLUG}]
**Preprocessing**

- 
JSON Path: `$.caches.length()`

|
|Repo [{#SLUG}]: Cache size|
Total size of cache files in {#SLUG} repo.
|Dependent item|travis.repo.caches.size[{#SLUG}]
**Preprocessing**

- 
JSON Path: `$.caches..size.sum()`

⛔️Custom on fail: Set value to: `0`

|
|Repo [{#SLUG}]: Builds passed|
Count of all passed builds in {#SLUG} repo.
|Dependent item|travis.repo.builds.passed[{#SLUG}]
**Preprocessing**

- 
JavaScript: `The text is too long. Please see the template.`

|
|Repo [{#SLUG}]: Builds failed|
Count of all failed builds in {#SLUG} repo.
|Dependent item|travis.repo.builds.failed[{#SLUG}]
**Preprocessing**

- 
JavaScript: `The text is too long. Please see the template.`

|
|Repo [{#SLUG}]: Builds total|
Count of total builds in {#SLUG} repo.
|Dependent item|travis.repo.builds.total[{#SLUG}]
**Preprocessing**

- 
JSON Path: `$.builds.length()`

|
|Repo [{#SLUG}]: Builds passed, %|
Percent of passed builds in {#SLUG} repo.
|Calculated|travis.repo.builds.passed.pct[{#SLUG}]|
|Repo [{#SLUG}]: Description|
Description of Travis repo (git project description).
|Dependent item|travis.repo.description[{#SLUG}]
**Preprocessing**

- 
JSON Path: `$.repositories[?(@.slug == "{#SLUG}")].description.first()`

- 
Discard unchanged with heartbeat: `1h`

|
|Repo [{#SLUG}]: Last build duration|
Last build duration in {#SLUG} repo.
|Dependent item|travis.repo.last_build.duration[{#SLUG}]
**Preprocessing**

- 
JSON Path: `$.builds[0].duration`

⛔️Custom on fail: Discard value

- 
Discard unchanged with heartbeat: `1h`

|
|Repo [{#SLUG}]: Last build state|
Last build state in {#SLUG} repo.
|Dependent item|travis.repo.last_build.state[{#SLUG}]
**Preprocessing**

- 
JSON Path: `$.builds[0].state`

- 
Discard unchanged with heartbeat: `1h`

|
|Repo [{#SLUG}]: Last build number|
Last build number in {#SLUG} repo.
|Dependent item|travis.repo.last_build.number[{#SLUG}]
**Preprocessing**

- 
JSON Path: `$.builds[0].number`

- 
Discard unchanged with heartbeat: `1h`

|
|Repo [{#SLUG}]: Last build id|
Last build id in {#SLUG} repo.
|Dependent item|travis.repo.last_build.id[{#SLUG}]
**Preprocessing**

- 
JSON Path: `$.builds[0].id`

- 
Discard unchanged with heartbeat: `1h`

|

### Trigger prototypes for Repos metrics discovery

|Name|Description|Expression|Severity|Dependencies and additional info|
|----|-----------|----------|--------|--------------------------------|
|Travis CI: Repo [{#SLUG}]: Percent of successful builds|
Low successful builds rate.
|`last(/Travis CI by HTTP/travis.repo.builds.passed.pct[{#SLUG}])<{$TRAVIS.BUILDS.SUCCESS.PERCENT}`|Warning|**Manual close**: Yes|
|Travis CI: Repo [{#SLUG}]: Last build status is 'errored'|
Last build status is errored.
|`find(/Travis CI by HTTP/travis.repo.last_build.state[{#SLUG}],,"like","errored")=1`|Warning|**Manual close**: Yes|

## Feedback

Please report any issues with the template at [`https://support.zabbix.com`](https://support.zabbix.com)

You can also provide feedback, discuss the template, or ask for help at [`ZABBIX forums`](https://www.zabbix.com/forum/zabbix-suggestions-and-feedback)

