|
| 1 | +--- |
| 2 | +title: "Nagios Integration" |
| 3 | +description: "Synchronize Nagios alert events to Flashduty via script to achieve automated alert noise reduction" |
| 4 | +date: "2025-05-19T10:00:00+08:00" |
| 5 | +url: "https://docs.flashcat.cloud/en/flashduty/nagios-integration-guide" |
| 6 | +--- |
| 7 | + |
| 8 | +Sync Nagios alert events to Flashduty via script to achieve automated alert noise reduction. |
| 9 | + |
| 10 | +<div class="hide"> |
| 11 | + |
| 12 | +## In Flashduty |
| 13 | +--- |
| 14 | +You can obtain an integration push URL through either of these two methods: |
| 15 | + |
| 16 | +### Using Private Integration |
| 17 | + |
| 18 | +Choose this method when you don't need to route alert events to different channels - it's simpler. |
| 19 | + |
| 20 | +<details> |
| 21 | + <summary>Expand</summary> |
| 22 | + |
| 23 | + 1. Go to the Flashduty console, select **Channel**, and enter a channel's details page |
| 24 | + 2. Select the **Integrations** tab, click **Add Integration** to enter the integration page |
| 25 | + 3. Choose **Nagios** integration and click **Save** to generate a card |
| 26 | + 4. Click the generated card to view the **Push URL**, copy it for later use, and you're done |
| 27 | + |
| 28 | +</details> |
| 29 | + |
| 30 | +### Using Shared Integration |
| 31 | + |
| 32 | +Choose this method when you need to route alerts to different channels based on the alert event payload. |
| 33 | + |
| 34 | +<details> |
| 35 | + <summary>Expand</summary> |
| 36 | + |
| 37 | + 1. Go to the Flashduty console, select **Integration Center=>Alert Events** to enter the integration selection page |
| 38 | + 2. Select **Nagios** integration: |
| 39 | + - **Integration Name**: Define a name for this integration |
| 40 | + 3. Configure the default route and select the corresponding channel (after the integration is created, you can go to `Route` to configure more routing rules) |
| 41 | + 4. Click **Save** and copy the newly generated **push URL** for later use |
| 42 | + 5. Done |
| 43 | + |
| 44 | +</details> |
| 45 | +</div> |
| 46 | + |
| 47 | + |
| 48 | +## In Nagios |
| 49 | + |
| 50 | +--- |
| 51 | + |
| 52 | +Nagios installation paths may vary depending on the system and installation method. Please adjust the paths in the following configuration according to your actual environment. |
| 53 | + |
| 54 | +### Step 1: Download Notification Script |
| 55 | + |
| 56 | +<div class="md-block"> |
| 57 | + |
| 58 | +Log in to the Nagios Server host and download the notification script to the Nagios plugin directory: |
| 59 | + |
| 60 | +- **Debian/Ubuntu systems** (typically `/usr/lib/nagios/plugins/`): |
| 61 | + |
| 62 | +```bash |
| 63 | +cd /usr/lib/nagios/plugins/ |
| 64 | +wget --header="Referer: https://console.flashcat.cloud" https://download.flashcat.cloud/flashduty/integration/nagios/send_to_flashduty.sh |
| 65 | +chmod +x send_to_flashduty.sh |
| 66 | +``` |
| 67 | + |
| 68 | +- **RHEL/CentOS systems** (typically `/usr/lib64/nagios/plugins/`): |
| 69 | + |
| 70 | +```bash |
| 71 | +cd /usr/lib64/nagios/plugins/ |
| 72 | +wget --header="Referer: https://console.flashcat.cloud" https://download.flashcat.cloud/flashduty/integration/nagios/send_to_flashduty.sh |
| 73 | +chmod +x send_to_flashduty.sh |
| 74 | +``` |
| 75 | + |
| 76 | +- **Source installation** (typically `/usr/local/nagios/libexec/`): |
| 77 | + |
| 78 | +```bash |
| 79 | +cd /usr/local/nagios/libexec/ |
| 80 | +wget --header="Referer: https://console.flashcat.cloud" https://download.flashcat.cloud/flashduty/integration/nagios/send_to_flashduty.sh |
| 81 | +chmod +x send_to_flashduty.sh |
| 82 | +``` |
| 83 | + |
| 84 | +#### Note: The script uses the `curl` command. Please ensure curl is installed on your Nagios Server. |
| 85 | + |
| 86 | +</div> |
| 87 | + |
| 88 | +### Step 2: Create Flashduty Configuration File |
| 89 | + |
| 90 | +<div class="md-block"> |
| 91 | + |
| 92 | +Download the Flashduty configuration file to the Nagios configuration directory: |
| 93 | + |
| 94 | +- **Debian/Ubuntu systems** (typically `/etc/nagios3/conf.d/`): |
| 95 | + |
| 96 | +```bash |
| 97 | +cd /etc/nagios3/conf.d/ |
| 98 | +wget --header="Referer: https://console.flashcat.cloud" https://download.flashcat.cloud/flashduty/integration/nagios/flashduty.cfg |
| 99 | +``` |
| 100 | + |
| 101 | +- **RHEL/CentOS systems** (typically `/etc/nagios/objects/`): |
| 102 | + |
| 103 | +```bash |
| 104 | +cd /etc/nagios/objects/ |
| 105 | +wget --header="Referer: https://console.flashcat.cloud" https://download.flashcat.cloud/flashduty/integration/nagios/flashduty.cfg |
| 106 | +``` |
| 107 | + |
| 108 | +- **Source installation** (typically `/usr/local/nagios/etc/objects/`): |
| 109 | + |
| 110 | +```bash |
| 111 | +cd /usr/local/nagios/etc/objects/ |
| 112 | +wget --header="Referer: https://console.flashcat.cloud" https://download.flashcat.cloud/flashduty/integration/nagios/flashduty.cfg |
| 113 | +``` |
| 114 | + |
| 115 | +</div> |
| 116 | + |
| 117 | +### Step 3: Modify Configuration File |
| 118 | + |
| 119 | +<div class="md-block"> |
| 120 | + |
| 121 | +Edit the downloaded `flashduty.cfg` file and modify the following: |
| 122 | + |
| 123 | +1. Replace the `pager` field value with the integration push URL obtained from the Flashduty console |
| 124 | +2. Modify the script path in `command_line` according to your Nagios installation path |
| 125 | + |
| 126 | +Configuration file example: |
| 127 | + |
| 128 | +``` |
| 129 | +define contact { |
| 130 | + contact_name Flashduty |
| 131 | + alias Flashduty Alert Receiver |
| 132 | + service_notification_commands notify-service-by-Flashduty |
| 133 | + host_notification_commands notify-host-by-Flashduty |
| 134 | + service_notification_options w,u,c,r |
| 135 | + host_notification_options d,u,r |
| 136 | + service_notification_period 24x7 |
| 137 | + host_notification_period 24x7 |
| 138 | + pager <YOUR_FLASHDUTY_PUSH_URL> |
| 139 | +} |
| 140 | +
|
| 141 | +
|
| 142 | +define command { |
| 143 | + command_name notify-host-by-Flashduty |
| 144 | + command_line <NAGIOS_PLUGIN_PATH>/send_to_flashduty.sh type=HOST WEBHOOK_URL="$CONTACTPAGER$" hostname="$HOSTNAME$" state="$HOSTSTATE$" output="$HOSTOUTPUT$" notification_type="$NOTIFICATIONTYPE$" time="$LONGDATETIME$" host_address="$HOSTADDRESS$" host_alias="$HOSTALIAS$" check_command="$HOSTCHECKCOMMAND$" |
| 145 | +} |
| 146 | +
|
| 147 | +define command { |
| 148 | + command_name notify-service-by-Flashduty |
| 149 | + command_line <NAGIOS_PLUGIN_PATH>/send_to_flashduty.sh type=SERVICE WEBHOOK_URL="$CONTACTPAGER$" hostname="$HOSTNAME$" state="$SERVICESTATE$" output="$SERVICEOUTPUT$" notification_type="$NOTIFICATIONTYPE$" time="$LONGDATETIME$" host_address="$HOSTADDRESS$" service_desc="$SERVICEDESC$" host_alias="$HOSTALIAS$" max_attempts="$MAXSERVICEATTEMPTS$" |
| 150 | +} |
| 151 | +``` |
| 152 | + |
| 153 | +Parameter descriptions: |
| 154 | +- `pager`: Flashduty push URL, the integration push URL obtained from the Flashduty console |
| 155 | +- `<NAGIOS_PLUGIN_PATH>`: Replace with the actual script path, such as `/usr/local/nagios/libexec` |
| 156 | +- `service_notification_options`: Service alert notification options, w=warning, u=unknown, c=critical, r=recovery |
| 157 | +- `host_notification_options`: Host alert notification options, d=down, u=unreachable, r=recovery |
| 158 | + |
| 159 | +**To include additional information in alerts, you can append parameters in `key=value` format at the end of `command_line`, for example: `environment="production" region="$_HOSTREGION$"`. These parameters will be pushed to Flashduty as labels.** |
| 160 | + |
| 161 | +</div> |
| 162 | + |
| 163 | +### Step 4: Include Configuration File |
| 164 | + |
| 165 | +<div class="md-block"> |
| 166 | + |
| 167 | +If you are using **RHEL/CentOS systems** or **source installation**, you need to include the Flashduty configuration file in the Nagios main configuration file. |
| 168 | + |
| 169 | +- **RHEL/CentOS systems**: Edit `/etc/nagios/nagios.cfg` and add: |
| 170 | + |
| 171 | +``` |
| 172 | +cfg_file=/etc/nagios/objects/flashduty.cfg |
| 173 | +``` |
| 174 | + |
| 175 | +- **Source installation**: Edit `/usr/local/nagios/etc/nagios.cfg` and add: |
| 176 | + |
| 177 | +``` |
| 178 | +cfg_file=/usr/local/nagios/etc/objects/flashduty.cfg |
| 179 | +``` |
| 180 | + |
| 181 | +:::tips |
| 182 | +Debian/Ubuntu systems typically auto-load all configuration files in the `/etc/nagios3/conf.d/` directory, so manual inclusion is not required. |
| 183 | +::: |
| 184 | + |
| 185 | +</div> |
| 186 | + |
| 187 | +### Step 5: Add Flashduty to Contact Group |
| 188 | + |
| 189 | +<div class="md-block"> |
| 190 | + |
| 191 | +Edit the contacts configuration file to add the Flashduty contact to the `admins` contact group (or another contact group you use): |
| 192 | + |
| 193 | +- **Debian/Ubuntu systems**: Edit `/etc/nagios3/conf.d/contacts_nagios2.cfg` |
| 194 | +- **RHEL/CentOS systems**: Edit `/etc/nagios/objects/contacts.cfg` |
| 195 | +- **Source installation**: Edit `/usr/local/nagios/etc/objects/contacts.cfg` |
| 196 | + |
| 197 | +Find the contact group definition and add Flashduty to the members list: |
| 198 | + |
| 199 | +``` |
| 200 | +define contactgroup { |
| 201 | + contactgroup_name admins |
| 202 | + alias Nagios Administrators |
| 203 | + members nagiosadmin,Flashduty |
| 204 | +} |
| 205 | +``` |
| 206 | + |
| 207 | +</div> |
| 208 | + |
| 209 | +### Step 6: Verify Configuration and Restart Service |
| 210 | + |
| 211 | +<div class="md-block"> |
| 212 | + |
| 213 | +1. Verify the Nagios configuration file: |
| 214 | + |
| 215 | +- **Debian/Ubuntu systems**: |
| 216 | + |
| 217 | +```bash |
| 218 | +/usr/sbin/nagios3 -v /etc/nagios3/nagios.cfg |
| 219 | +``` |
| 220 | + |
| 221 | +- **RHEL/CentOS systems**: |
| 222 | + |
| 223 | +```bash |
| 224 | +/usr/sbin/nagios -v /etc/nagios/nagios.cfg |
| 225 | +``` |
| 226 | + |
| 227 | +- **Source installation**: |
| 228 | + |
| 229 | +```bash |
| 230 | +/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg |
| 231 | +``` |
| 232 | + |
| 233 | +2. If verification passes, restart the Nagios service: |
| 234 | + |
| 235 | +```bash |
| 236 | +# Debian/Ubuntu |
| 237 | +systemctl restart nagios3 |
| 238 | +# or |
| 239 | +service nagios3 restart |
| 240 | + |
| 241 | +# RHEL/CentOS/Source installation |
| 242 | +systemctl restart nagios |
| 243 | +# or |
| 244 | +service nagios restart |
| 245 | +``` |
| 246 | + |
| 247 | +3. After configuration is complete, Nagios will automatically push alerts to Flashduty when detected |
| 248 | + |
| 249 | +</div> |
| 250 | + |
| 251 | +## Status Mapping |
| 252 | + |
| 253 | +--- |
| 254 | + |
| 255 | +<div class="md-block"> |
| 256 | + |
| 257 | +Nagios to Flashduty alert severity mapping: |
| 258 | + |
| 259 | +| Nagios | Flashduty | Status | |
| 260 | +| --------------- | --------- | -------- | |
| 261 | +| CRITICAL | Critical | Critical | |
| 262 | +| DOWN | Critical | Critical | |
| 263 | +| UNREACHABLE | Critical | Critical | |
| 264 | +| WARNING | Warning | Warning | |
| 265 | +| OK | Ok | Recovered | |
| 266 | +| UP | Ok | Recovered | |
| 267 | +| UNKNOWN | Info | Info | |
| 268 | + |
| 269 | +</div> |
0 commit comments