\documentclass{ictlab}

% Copyright (c) 2003 by Nick Urbanik <nicku(at)nicku.org>.
% This material may be distributed only subject to the terms and
% conditions set forth in the Open Publication License, v1.0 or later
% (the latest version is presently available at
% http://www.opencontent.org/openpub/).

\RCS $Revision: 1.3 $

\usepackage{verbatim,alltt}
\usepackage[hang,bf,nooneline]{caption2}
\ifx\pdftexversion\undefined \else
  \usepackage[pdfpagemode=None,pdfauthor={Nick Urbanik}]{hyperref}
\fi

\newcommand*{\labTitle}{SNMP Operations}
\providecommand*{\SNMP}{\acro{SNMP}\xspace}
\providecommand*{\MIB}{\acro{MIB}\xspace}
\providecommand*{\ID}{\acro{ID}\xspace}
\providecommand*{\OID}{\acro{OID}\xspace}
\renewcommand{\floatpagefraction}{0.75} % default is .5, to increase
% density.
\renewcommand*{\bottomfraction}{0.6} % default is 0.3
\renewcommand*{\topfraction}{0.85} % default is 0.7
\renewcommand*{\textfraction}{0.1} % default is 0.2


\begin{document}
\section{Background}
\label{background}

The Net-\SNMP tools are useful particularly since they implement
aspects of the protocol in a simple, understandable way, and are ideal
for learning about the \SNMP protocol.  They are also useful
troubleshooting tools.  The tool \texttt{snmpget} implements the
\texttt{get-request} part of the \SNMP protocol.  Read the man page
for \texttt{snmpcmd} and make sure you understand what you are doing.

\subsection{The \texttt{get-request} Operation}
\label{sec:get-request}

\begin{figure}[htb]
  \centering%
  \includegraphics{get-response}
  \caption{A manager sends an \SNMP \texttt{get-request} to an agent, which
    sends a \texttt{response} to the manager.}
  \label{fig:get-response}
\end{figure}

Figure~\vref{fig:get-response} shows a \emph{manager} sending an \SNMP
\texttt{get-request} to an \emph{agent} running on a managed network
device, such as a network switch or network server.  The
\texttt{get-request} contains one or more \OID{}s.  The agent responds
by sending back the data associated with each \OID.

\subsection{Instance Numbers}
\label{sec:instance-numbers}

Managed objects come in two main types:
\begin{itemize}
\item scalars, and
\item tables.
\end{itemize}
The \OID of each managed object ends with an \emph{instance number}.
The instance number is zero for a scalar, and is equal to the index
for a table entry.  We will look at \SNMP tables in detail later.  The
instance numbers for table entries start from the value 1.

\section{Procedure}
\begin{enumerate}
\item The \texttt{snmpget} command can be used to retrieve data from a
  remote host given its host name, authentication information and an
  \OID. As a simple example:
\begin{alltt}
$ \textbf{snmpget -v 1 -c public nicku.org system.sysUpTime.0}
\end{alltt}%$
% system.sysUpTime.0 = Timeticks: (586731977) 67 days, 21:48:39.77

In the above example, \texttt{nicku.org} is the host
name we wanted to talk to, using the \SNMP community string
\texttt{public} and we requested the value of the \OID{}
\texttt{system.sysUpTime.0}, using \SNMP protocol version 1.


\item We used \SNMP{}v1 here.  \SNMP{}v2c, which is similar in nature
  to \SNMP{}v1 with small modifications, still uses clear-text
  community names as ``passwords'' to authenticate the sender of the
  command.  The result from a command using the \SNMP{}v2c version is
  the same:

\begin{alltt}
$ \textbf{snmpget -v 2c -c public nicku.org system.sysUpTime.0}
\end{alltt}%$
% system.sysUpTime.0 = Timeticks: (586752671) 67 days, 21:52:06.71


\item All of the utilities allow abbreviation of the \OID{}s and do
  random searches by default, (like \texttt{snmptranslate} with its
  \texttt{-IR} option), and so if you like, you can specify a small
  part of the \OID:
\begin{alltt}
$ \textbf{snmpget -v 2c -c public nicku.org sysUpTime.0}
\end{alltt}%$
% system.sysUpTime.0 = Timeticks: (586752671) 67 days, 21:52:06.71


\item A common mistake when using the \texttt{snmpget} command is to
  leave off the \emph{instance number} of the data you're looking
  for.  See section~\vref{sec:instance-numbers}.
  In the above commands, the variable requested by the \OID{} is a
  scalar and the instance number for scalars is always a simple
  `\texttt{0}' (zero), hence the trailing `\texttt{.0}' in all the
  oids above. If you had left it off, you would have gotten an error.
  Note that the errrors differ slightly between \SNMP{}v1 and \SNMP{}v2c:
\begin{alltt}
$ \textbf{snmpget -v 1 -c public nicku.org sysUpTime}
Error in packet
Reason: (noSuchName) There is no such variable name in this MIB.
Failed object: system.sysUpTime

$ \textbf{snmpget -v 2c -c public nicku.org sysUpTime}
system.sysUpTime = No Such Instance currently exists
\end{alltt}


\item Multiple variables can be retrieved in one transaction as well:

\begin{alltt}
$ \textbf{snmpget -v 2c -c public nicku.org sysUpTime.0 sysContact.0}
\end{alltt}%$
% system.sysUpTime.0 = Timeticks: (586903243) 67 days, 22:17:12.43
% enterprises.ucdavis.ucdDemoMIB.ucdDemoMIBObjects.ucdDemoPublic.ucdDemoUserList.0 = " noAuthUser MD5User MD5DESUser SHAUser SHADESUser"

\item Do you think that the tool \texttt{snmpget} functions in the
  role of an \emph{agent} or in the role of a \emph{manager}?

\item Now use \texttt{snmptranslate -Tp} and the documentation for the
  tools in the software package \texttt{net-snmp-utils} to determine
  the load average on \texttt{nicku.org}.  Compare the
  readings you get with:
\begin{alltt}
$ \textbf{ssh ictlab uptime}   
 10:01am  up 14 days, 26 min,  9 users,  load average: 0.29, 0.24, 0.16
\end{alltt}%$
\begin{explanation}
  Hint: try piping the output of \texttt{snmptranslate -Tp} through
  \texttt{grep -i load}.  The option \texttt{-C5} to \texttt{grep} may
  help.  This prints 5 lines before and after the matching line.
\end{explanation}
\end{enumerate}
\end{document}
