# Nagios

Follow the steps below to configure a service so as to push related alert data from Nagios onto Squadcast.

Squadcast will then process this information to create incidents for this service as per your preferences.

### Using Nagios as an Alert Source

1. Navigate to **Services** -> **Service Overview** -> select or search for your Service. Expand the accordion -> In the Alert Sources section, click **Add**.

![](https://1574591692-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8TaWz01jmUJl58p4ZVel%2Fuploads%2Fgit-blob-4fbd74e7ca0b30173c47a1d58ed6a0804a0465aa%2FAlert_Sources.png?alt=media\&token=aaca6610-9d18-4dd4-9cf5-320042f326f1)

2\. Select **Nagios.** Copy the displayed **Webhook URL** to [configure](#create-a-squadcast-webhook-in-nagios) it within **Nagios**. Finish by clicking **Add Alert Source** -> **Done.**

![](https://1574591692-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8TaWz01jmUJl58p4ZVel%2Fuploads%2Fgit-blob-7da3448f70b3ed3e6df66f2b4aff1d1052c3a8cd%2FNagios.png?alt=media\&token=0314bc55-8227-42a3-8bff-d1990ade4119)

{% hint style="warning" %}
**Important:**

When an alert source turns Active, it’ll show up under Configured Alert Sources, you can either generate a test alert from the integration or wait for a real-time alert to be generated by the Alert Source. An Alert Source is active if there is a recorded incident via that Alert Source for the Service.
{% endhint %}

{% hint style="info" %}
Nagios Core versions 3.x and above are supported
{% endhint %}

### Create a Squadcast Webhook in Nagios

* Log in to your Nagios server and go to your **nagios.cfg** file (usually in `/usr/local/nagios/etc/` or `/etc/nagios`). Make sure **enable\_environment\_macros=1**. You can find the path of all your object config files and resource config file here. Go to **$USER1$** directory. You can find the value of this macro in your resource.cfg file.
* Once you're inside the directory, run the following commands:

```
sudo wget https://raw.githubusercontent.com/squadcastHub/squadcast-nagios-script/master/sq-nagios-service.py
sudo wget https://raw.githubusercontent.com/squadcastHub/squadcast-nagios-script/master/sq-nagios-host.py
```

* Once the file is downloaded please make sure that the file has execute permissions for your Nagios user. If not, then please provide the same using the following commands:

```
sudo chmod +x sq-nagios-service.py
sudo chmod +x sq-nagios-host.py
```

{% hint style="info" %}
The Squadcast script for Nagios requires Python 3 to be installed on the machine running Nagios.
{% endhint %}

* Go to **commands.cfg** file. Then add the following two commands:

```
# 'service-alert' command definition
define command{
        command_name    service-alert
        command_line    $USER1$/sq-nagios-service.py 'https://api.squadcast.com/v1/incidents/nagios/c2165ee4e7635e337b3ae529ec5c851e6876e5a8' '$HOSTNAME$' '$SERVICEDESC$' '$SERVICESTATE$' '$SERVICEOUTPUT$' '$HOSTADDRESS$'
}

# 'host-alert' command definition
define command{
        command_name    host-alert
        command_line    $USER1$/sq-nagios-host.py 'https://api.squadcast.com/v1/incidents/nagios/c2165ee4e7635e337b3ae529ec5c851e6876e5a8' '$HOSTNAME$' '$HOSTSTATE$' '$HOSTOUTPUT$' '$HOSTADDRESS$'

}
```

{% hint style="info" %}
Make Sure to replace the url with the webhook url you copied from Squadcast Dashboard
{% endhint %}

* Go to **contacts.cfg** file.

Create a new contact and set your notification\_options and notification\_period for service and host according to your preference.

Enable host\_notifications and service\_notifications

Set service\_notification\_commands to service-alert and host\_notification\_commands to host-alert

Ex:

```
define contact {
        contact_name squadcast
        alias Squadcast
        host_notifications_enabled      1
        service_notifications_enabled   1
        service_notification_period 24x7
        host_notification_period 24x7
        service_notification_options w,u,c,r
        host_notification_options d,u,r
        service_notification_commands service-alert
        host_notification_commands host-alert
}
```

* Then add the contact to your preferred **contact group**.

Ex:

```
define contactgroup{
        contactgroup_name       admins
        alias                   Nagios Administrators
        members                 nagiosadmin,squadcast
        }
```

* Finally restart Nagios using the following command:

```
service nagios restart
```

Now whenever an event is triggered in Nagios, an incident will be automatically created in Squadcast. Also, once the event that triggered the incident(s) is resolved in Nagios, the relevant Squadcast incidents created would get resolved automatically.

*Have any questions?* [*Ask the community*](https://community.squadcast.com/view/home)*.*
