> ## Documentation Index
> Fetch the complete documentation index at: https://docs.allquiet.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Nagios

> Connect Nagios Monitoring with All Quiet

<Info>Setup time: 10 Min</Info>

Integrate Nagios Monitoring with All Quiet in a matter of minutes. With webhooks, you can automatically send alerts from Nagios directly to All Quiet, streamlining your team's incident management process.

## 1. Create Nagios Integration on All Quiet

Sign in to your All Quiet account.

### Create Integration

1. Click on the `Inbound Integrations` tab.
2. Click on `+ Create`.

<img className="Nagios_Create" src="https://mintcdn.com/allquiet/LprUf3XBqV5kYbwv/images/nagios/01.png?fit=max&auto=format&n=LprUf3XBqV5kYbwv&q=85&s=d4009ce364b3141cc6b45720028bb73c" width="2740" height="678" data-path="images/nagios/01.png" />

### Select Nagios as the integration's type

1. Enter a `Display Name` for your integration, e.g. "Nagios".
2. Select a `Team`.
3. Select `Nagios` as the integration's type.
4. Click `Create Inbound Integration`.

<img className="Nagios_Select" src="https://mintcdn.com/allquiet/LprUf3XBqV5kYbwv/images/nagios/02.png?fit=max&auto=format&n=LprUf3XBqV5kYbwv&q=85&s=945908a7de06b423597eb85385bd9760" width="2137" height="2220" data-path="images/nagios/02.png" />

### Get the All Quiet Webhook URL

After creating the integration on All Quiet, you can view and copy the webhook URL. You will require this URL in step 2 when configuring the custom integration on Nagios.

<img className="Nagios_Get" src="https://mintcdn.com/allquiet/LprUf3XBqV5kYbwv/images/nagios/03.png?fit=max&auto=format&n=LprUf3XBqV5kYbwv&q=85&s=6b0f610be1c8454728f9ee29952b3978" width="2182" height="938" data-path="images/nagios/03.png" />

## 2. Configure the Integration with Nagios

Once you've set up an integration of type "Nagios" with All Quiet, it takes only four steps in your Nagios configuration to finish off your setup.

### Add All Quiet Notification Scripts for Nagios

Nagios differentiates between `Hosts` and `Services`. Depending on which of these you want to monitor with All Quiet, you need to add the respective shell script from below to a folder where Nagios can execute it, for instance `/usr/local/bin/allquiet/`.

```sh notify-allquiet-host.sh theme={null}
#!/usr/bin/env bash
set -euo pipefail

allquiet_webhook_url="$1"
nagios_url="$2"
notification_type="$3"
state="$4"
host="$5"
alias="$6"
output="$7"
problem_id="$8"
last_problem_id="$9"

correlation_problem_id="$problem_id"
if [ "$correlation_problem_id" = "0" ]; then
  correlation_problem_id="$last_problem_id"
fi

correlation_id="${host}:${correlation_problem_id}"

curl -sS -m 10 --fail -X POST \
  "${allquiet_webhook_url}" \
  -d "title=[${notification_type}] Host ${host}" \
  -d "src=host" \
  -d "type=${notification_type}" \
  -d "status=${state}" \
  -d "host=${host}" \
  -d "alias=${alias}" \
  -d "output=${output}" \
  -d "id=${correlation_problem_id}" \
  -d "link=${nagios_url}/cgi-bin/extinfo.cgi?type=1%26host=${host}" \
  -d "correlation_id=${correlation_id}" 
```

```sh notify-allquiet-service.sh theme={null}
#!/usr/bin/env bash
set -euo pipefail

allquiet_webhook_url="$1"
nagios_url="$2"
notification_type="$3"
state="$4"
service="$5"
host="$6"
output="$7"
problem_id="$8"
last_problem_id="$9"

correlation_problem_id="$problem_id"
if [ "$correlation_problem_id" = "0" ]; then
  correlation_problem_id="$last_problem_id"
fi

correlation_id="${host}:${service}:${correlation_problem_id}"

curl -sS -m 10 --fail -X POST \
  "${allquiet_webhook_url}" \
  -d "title=[${notification_type}] ${service} (${host})" \
  -d "src=service" \
  -d "status=${state}" \
  -d "type=${notification_type}" \
  -d "service=${service}" \
  -d "host=${host}" \
  -d "output=${output}" \
  -d "id=${correlation_problem_id}" \
  -d "link=${nagios_url}/cgi-bin/extinfo.cgi?type=2%26host=${host}%26service=${service}" \
  -d "correlation_id=${correlation_id}"
```

To finish this step, you need to ensure that the scripts are executable. Therefore, please run the following commands in the folders the scripts are saved in.

```txt Commands for Service and Host files; here named notify-allquiet-service.sh and notify-allquiet-hosts.sh  theme={null}
chmod +x {path}/notify-allquiet-service.sh
chmod +x {path}/notify-allquiet-host.sh
```

### Add Commands

Next, to send alerts to All Quiet, we need to define the commands.
Here, Nagios also differentiates between `Host` and `Service` commands.

Below, you find templates for both types of commands that you can paste into your `commands.cfg`, depending on which type(s) your are using.

<Tip>Make sure to **adjust lines 3-5** depending on your path, file name, Webhook URL from [previous step](/integrations/inbound/nagios#get-the-all-quiet-webhook-url) and your Nagios domain.</Tip>

```cfg Service Command highlight={3-5} lines theme={null}
define command {
    command_name    notify-allquiet-service    
    command_line    /usr/local/bin/allquiet/notify-allquiet-service.sh \
                "https://YOUR_WEBHOOK__URL_FROM_STEP_1" \
                "https://YOUR_NAGIOS_DOMAIN" \
                "$NOTIFICATIONTYPE$" \
                "$SERVICESTATE$" \
                "$SERVICEDESC$" \
                "$HOSTNAME$" \
                "$SERVICEOUTPUT$" \
                "$SERVICEPROBLEMID$" \
                "$LASTSERVICEPROBLEMID$"
}
```

```cfg Host Command highlight={3-5} lines theme={null}
define command {
    command_name    notify-allquiet-host
    command_line    /usr/local/bin/allquiet/notify-allquiet-host.sh \
                "https://YOUR_WEBHOOK__URL_FROM_STEP_1" \
                "https://YOUR_NAGIOS_DOMAIN" \
                "$NOTIFICATIONTYPE$" \
                "$HOSTSTATE$" \
                "$HOSTNAME$" \
                "$HOSTALIAS$" \
                "$HOSTOUTPUT$" \
                "$HOSTPROBLEMID$" \
                "$LASTHOSTPROBLEMID$"
}
```

Make sure to save your `commands.cfg`.

### Add All Quiet Contact

Next, we need to add All Quiet as a contact to your `contacts.cfg` in Nagios.

<Tip> Make sure to include your command(s) name(s) from above.</Tip>

```cfg Example Contact highlight={8-9} theme={null}
define contact {
    contact_name                    allquiet
    alias                           All Quiet
    service_notification_period     24x7
    host_notification_period        24x7
    service_notification_options    w,u,c,r
    host_notification_options       d,r
    service_notification_commands   notify-allquiet-service
    host_notification_commands      notify-allquiet-host
    email                           none@example.com
}
```

Make sure to save your `contacts.cfg`.

### Add Contact to Your Services and Hosts

Last but not least, you need to add the contact (here: `allquiet`) to your defined `Service(s)` and / or `Host(s)`, allowing you to trigger the Nagios Commands if your `Services` or `Hosts` report an issue.

```cfg Add Contact to Your Services and Hosts theme={null}
...
contact     allquiet
...
```

Afterwards Make sure to save your Nagios config and restart to apply changes.

<Check> You're ready to go. If you set up your integration this way, Nagios alerts will automatically create and update All Quiet incidents.</Check>

### Adjust Payload Mapping

Looking to customize the fields of your incidents by adjusting the pre-built payload mapping? Simply head over to the “Payload” tab within your integration and make the necessary edits to the mapping. For detailed guidance, you may check out our [payload mapping documentation](/essentials/inbound#how-does-attribute-mapping-work).

<Tip>Using our Terraform provider? [Download](https://allquiet.app/api/integrations/terraform/default/Nagios.tf) the default mapping of the `allquiet_integration_mapping` resource for the Nagios integration. Simply copy the syntax to your .tf file and tailor the resource to your team's needs!</Tip>
