Difference between pages "Piping" and "Snmp"

From Linuxintro
(Difference between pages)
imported>ThorstenStaerk
(New page: The most fascinating thing about Unix is how the following works together: * the way Unix treats streams * the paradigm "everything is a file" * the paradigm "do one thing and do it well" ...)
 
imported>ThorstenStaerk
 
Line 1: Line 1:
The most fascinating thing about Unix is how the following works together:
+
Trying to build an SNMP prototype
* the way Unix treats streams
 
* the paradigm "everything is a file"
 
* the paradigm "do one thing and do it well"
 
  
Let's start with the most basic program: cat. cat inputs a "stream" and outputs a "stream", nothing else. Find it out like this:
+
SUSE Linux:
poochy:~ # cat
 
Hello, I am typing a line
 
Hello, I am typing a line
 
After typing cat with no parameters, you can ''input'' a line (followed by ENTER). cat does nothing but ''output'' the line again. You end your input with CTRL_D. Standard for your input is the keyboard, standard for a program's output is the console.
 
  
'''''How can this be useful?'''''
+
yast -i nagios apache2
 +
/etc/init.d/nagios start
 +
http://127.0.0.1/nagios
 +
log in as nagiosadmin:nagiosadmin
 +
/etc/init.d/snmptrapd
 +
tail -f /var/log/net-snmpd.log
 +
snmptrap -v 2c -c public localhost "" NET-SNMP-EXAMPLES-MIB::netSnmpExampleHeartbeatNotification netSnmpExampleHeartbeatRate i 42
  
This can be extremely useful. E.g. take the paradigm "everything is a file". So you can replace your ''input stream'' by a file using a parameter:
+
  No access configuration - dropping trap.
  cat ''readme.txt''
 
outputs the content of ''readme.txt'' to the console. So you can display a file.
 
  
Or you can redirect cat's output ''stream'' to a file using the > operator:
+
So it seems I have to  
cat > myfile.txt
 
Allows you to (over)write directly the file ''myfile.txt''.
 
  
Or you can redirect the output of cat to the input of another command using the | (pipe) operator:
+
cat /etc/snmp/snmptrapd.conf
  cat myfile.txt | cat
+
  disableAuthorization yes
is equivalent to cat myfile.txt.
+
traphandle default /bin/snmppl
  
'''''How can this pipe be useful?'''''
+
/etc/init.d/snmptrapd restart
 +
cat /bin/snmppl
 +
#!/bin/bash
 +
date >>/tmp/dates
  
There is a command to search a string in a stream (yes, or in a file, because everything is a file), called grep.
+
= See also =
grep needle
+
* http://nagios.sourceforge.net/docs/3_0/quickstart-opensuse.html
takes an input stream and echos only those lines containing the string "needle":
+
* http://net-snmp.sourceforge.net/wiki/index.php/TUT:snmptrap
poochy:/usr # grep needle
 
haystack
 
hay
 
more hay
 
even more hay
 
needle
 
needle
 
again hay
 
some more hay
 
 
 
Now if we combine cat and grep, we get
 
cat * | grep needle
 
"*" stands for "all files". This command searches in all files for the string "needle" and outputs the files that contain it. Just FYI, this is equivalent to
 
grep "needle" *
 
because, as said, you can hand over files to grep.
 

Revision as of 16:46, 4 April 2014

Trying to build an SNMP prototype

SUSE Linux:

yast -i nagios apache2
/etc/init.d/nagios start
http://127.0.0.1/nagios

log in as nagiosadmin:nagiosadmin

/etc/init.d/snmptrapd
tail -f /var/log/net-snmpd.log
snmptrap -v 2c -c public localhost "" NET-SNMP-EXAMPLES-MIB::netSnmpExampleHeartbeatNotification netSnmpExampleHeartbeatRate i 42
No access configuration - dropping trap.

So it seems I have to

cat /etc/snmp/snmptrapd.conf
disableAuthorization yes
traphandle default /bin/snmppl
/etc/init.d/snmptrapd restart
cat /bin/snmppl
#!/bin/bash
date >>/tmp/dates

See also