Skip to content

Commit a8082d9

Browse files
committed
trap update
1 parent 09b3337 commit a8082d9

File tree

1 file changed

+62
-2
lines changed

1 file changed

+62
-2
lines changed

content/en/docs/coshsh/snmp_traps/_index.md

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,19 @@ SNMP Traps and Nagios (or any other related systems) is one of those topics that
1111
Let's start with a picture. A network device sends traps to the OMD server. Here we have a process [samplicate](https://github.com/sleinen/samplicator) listening on port 162 which duplicates the udp packets and forwards them to the OMD sites which are configured as trap recipients, Such sites have an *snmptrapd* process, which writes the contents of an incoming trap in a logfile, *traps.log*. (we see three traps here, arriving at port 162 in the order blue, green, red. In the same order they arrive at the sites' snmptrap daemons and in the same order they are written to the logfile)
1212
That's all. Later you will learn how the logfile is scanned for incoming traps, how these are evaluated, how the trap sender is identified among the monitored host objects and how the right service is set into an alarm state.
1313

14-
1514
![trap distribution](./samplicate-omd.png)
15+
<!--
16+
You need:
17+
a PC which acts as the trap sender
18+
a VM with OMD which acts as trap destination and monitoring server
19+
create an omd site
20+
edit etc/environment OMD_LANDSCAPE=lab
21+
share/coshsh/contrib/coshsh-prepar-landscape
22+
-->
23+
1624

1725
## Setup trap processing on an OMD server
18-
The first part of this article focuses on preparing an OMD server. Specifically, it explains how to ensure that an incoming trap is simultaneously forwarded to multiple OMD sites (e.g., testing, production, etc.).
26+
The first part of this article focuses on preparing an OMD server. Specifically, in the end it will explains how to ensure that an incoming trap is simultaneously forwarded to multiple OMD sites (e.g., testing, production, etc.).
1927

2028
First, any existing snmptrapd process must be stopped, and its associated init script or systemd service must be removed. With most distributions this is achieved by running the following commands as the root user:
2129
```bash
@@ -122,6 +130,58 @@ Total translations: 1
122130
Successful translations: 1
123131
Failed translations: 0
124132
```
133+
134+
### Prepare Coshsh and create a trap-sending host
135+
You probably executed the **snmptrap** command on a Windows or Linux host. Let's configureCoshsh and OMD so that this host ist being monitored and its traps are triggering an alarm.
136+
The "CMDB" we will use is a set of CSV files, located in *etc/coshsh/data*. The first one describes attributes of the host will be used to shape the host object in Naemon. For the example we fake a notional appliance of type *Blackenbox* running the *HeartbeatOS*
137+
```csv
138+
# host_name,address,type,os,hardware,virtual,notification_period,location,department
139+
sender,192.168.1.1,appliance,heartbeat,rpi,0,24x7,lab,rnd
140+
```
141+
_File: etc/coshsh/conf.d/trapdemo_hosts.csv_
142+
143+
We describe the firmware/operating system in the following file:
144+
```csv
145+
# host_name,name,type,component,version,check_period
146+
sender,os,heartbeatos,,1.0,24x7
147+
```
148+
_File: etc/coshsh/conf.d/trapdemo_applications.csv_
149+
150+
Then we need a Python class for *HeartbeatOS*, for which we create a file *etc/coshsh/recipes/trapdemo/classes/os_heartbeatos.py* with the following content:
151+
152+
```python
153+
import coshsh
154+
from coshsh.application import Application
155+
from coshsh.templaterule import TemplateRule
156+
from coshsh.util import compare_attr, is_attr
157+
158+
def __mi_ident__(params={}):
159+
if coshsh.util.is_attr("name", params, "os") and coshsh.util.compare_attr("type", params, ".*heartbeatos.*"):
160+
return HeartbeatOS
161+
162+
163+
class HeartbeatOS(Application):
164+
template_rules = []
165+
implements_mibs = ['NET-SNMP-EXAMPLES-MIB']
166+
```
167+
_File: etc/coshsh/recipes/trapdemo/classes/os_heartbeatos.py_
168+
169+
```ini
170+
[datasource_trapdemo]
171+
type = csv
172+
dir = %OMD_ROOT%/etc/coshsh/data
173+
174+
[recipe_trapdemo]
175+
datasources = trapdemo,snmptt
176+
objects_dir = %OMD_ROOT%/var/coshsh/configs/trapdemo/
177+
```
178+
_File: etc/coshsh/conf.d/trapdemo.conf_
179+
180+
```bash
181+
OMD[demo@pxmxmon]:~$ coshsh-cook --cookbook $HOME/etc/coshsh/conf.d/trapdemo.conf \
182+
--recipe trapdemo
183+
OMD[demo@pxmxmon]:~$ check_git_updates
184+
```
125185
<!--
126186
SORRY FROM HERE ON THERE IS WORK-IN-PROGRESS BECAUSE I GO HOME NOW AND CONTINUE FROM THERE
127187

0 commit comments

Comments
 (0)