1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- This document was generated using DocBuilder 3.3.3 -->
<HTML>
<HEAD>
<TITLE>snmp_generic</TITLE>
<SCRIPT type="text/javascript" src="../../../../doc/erlresolvelinks.js">
</SCRIPT>
<STYLE TYPE="text/css">
<!--
.REFBODY { margin-left: 13mm }
.REFTYPES { margin-left: 8mm }
-->
</STYLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#FF00FF"
ALINK="#FF0000">
<!-- refpage -->
<CENTER>
<A HREF="http://www.erlang.se">
<IMG BORDER=0 ALT="[Ericsson AB]" SRC="min_head.gif">
</A>
<H1>snmp_generic</H1>
</CENTER>
<H3>MODULE</H3>
<DIV CLASS=REFBODY>
snmp_generic
</DIV>
<H3>MODULE SUMMARY</H3>
<DIV CLASS=REFBODY>
Generic Functions for Implementing SNMP Objects in a
Database
</DIV>
<H3>DESCRIPTION</H3>
<DIV CLASS=REFBODY>
<P>The module <CODE>snmp_generic</CODE> contains generic functions for implementing tables
(and variables) using the SNMP built-in database or Mnesia. These
default functions are used if no instrumentation function is
provided for a managed object in a MIB. Sometimes, it might be
necessary to customize the behaviour of the default functions. For
example, in some situations a trap should be sent if a row is
deleted or modified, or some hardware is to be informed, when
information is changed.
<P>The overall structure is shown in the following figure:
<PRE>
+---------------+
| SNMP Agent |
+- - - - - - - -+
| MIB |
+---------------+
|
Association file (associates a MIB object with
| snmp_generic:table_funct
| snmp_generic:variable_func)
+--------------------------------------+
| snmp_generic | Support for get-next,
| | RowStatus operations
+----------------------+---------------+
| snmpa_local_db | Mnesia | Database
+--------------+-------+---------------+
| dets | ets |
| (persistent) | |
+--------------+-------+
</PRE>
<P>Each function takes the argument <CODE>NameDb</CODE>, which is a
tuple <CODE>{Name, Db}</CODE>, to identify which database the
functions should use. <CODE>Name</CODE> is the symbolic name of the
managed object as defined in the MIB, and <CODE>Db</CODE> is either
<CODE>volatile</CODE>, <CODE>persistent</CODE>, or <CODE>mnesia</CODE>. If it is
<CODE>mnesia</CODE>, all variables are stored in the Mnesia table
<CODE>snmp_variables</CODE> which must be a table with two attributes
(not a Mnesia SNMP table). The SNMP tables are stored in Mnesia
tables with the same names as the SNMP tables. All functions
assume that a Mnesia table exists with the correct name and
attributes. It is the programmer's responsibility to ensure
this. Specifically, if variables are stored in Mnesia, the table
<CODE>snmp_variables</CODE> must be created by the programmer. The
record definition for this table is defined in the file
<CODE>snmp/include/snmp_types.hrl</CODE>.
<P>If an instrumentation function in the association file for a
variable <CODE>myVar</CODE> does not have a name when compiling an
MIB, the compiler generates an entry.
<PRE>
{myVar, {snmp_generic, variable_func, [{myVar, Db]}}.
</PRE>
<P>And for a table:
<PRE>
{myTable, {snmp_generic, table_func, [{myTable, Db]}}.
</PRE>
<P>In the functions defined below, the following types are used:
<P><CODE>NameDb = {Name, Db}, Name = atom(), Db = volatile |
persistent | mnesia</CODE>
<P><CODE>RowIndex = [int()]</CODE>
<P><CODE>Cols = [Col] | [{Col, Value}], Col = int(), Value =
term()</CODE>
<P><CODE>RowIndex</CODE> denotes the last part of the OID which
specifies the index of the row in the table (see RFC1212, 4.1.6
for more information about INDEX). <CODE>Cols</CODE> is a list of
column numbers in the case of a <CODE>get</CODE> operation, and a list
of column numbers and values in the case of a <CODE>set</CODE>
operation. <CODE>Cols</CODE> is a list of column numbers in case of a
get operation, and a list of column numbers and values in case
of a set operation.
</DIV>
<H3>EXPORTS</H3>
<P><A NAME="get_status_col/2"><STRONG><CODE>get_status_col(Name,Cols)</CODE></STRONG></A><BR>
<A NAME="get_status_col/2"><STRONG><CODE>get_status_col(NameDb,Cols) -> {ok, StatusVal} | false</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Gets the value of the status column from <CODE>Cols</CODE>.
<P>This function can be used in instrumentation functions for
<CODE>is_set_ok</CODE>, <CODE>undo</CODE> or <CODE>set</CODE> to check if the
status column of a table is modified.
</DIV>
<P><A NAME="get_index_types/1"><STRONG><CODE>get_index_types(Name)</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Gets the index types of <CODE>Name</CODE>
<P>This function can be used in instrumentation functions to
retrieve the index types part of the table info.
</DIV>
<P><A NAME="table_func/2"><STRONG><CODE>table_func(Op1,NameDb)</CODE></STRONG></A><BR>
<A NAME="table_func/4"><STRONG><CODE>table_func(Op2,RowIndex,Cols,NameDb) -> Ret</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Op1 = new | delete </CODE></STRONG><BR>
<STRONG><CODE>Op2 = get | next | is_set_ok | set | undo</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>This is the default instrumentation function for tables.
<P>
<UL>
<LI>
The <CODE>new</CODE> function creates the table if it does
not exist, but only if the database is the SNMP internal db.
</LI>
<LI>
The <CODE>delete</CODE> function does not delete the table
from the database since unloading an MIB does not
necessarily mean that the table should be destroyed.
</LI>
<LI>
The <CODE>is_set_ok</CODE> function checks that a row which
is to be modified or deleted exists, and that a row which
is to be created does not exist.
</LI>
<LI>
The <CODE>undo</CODE> function does nothing.
</LI>
<LI>
The <CODE>set</CODE> function checks if it has enough
information to make the row change its status from
<CODE>notReady</CODE> to <CODE>notInService</CODE> (when a row has
been been set to <CODE>createAndWait</CODE>). If a row is set to
<CODE>createAndWait</CODE>, columns without a value are set to
<CODE>noinit</CODE>. If Mnesia is used, the set functionality is
handled within a transaction.
</LI>
</UL>
<P>If it is possible for a manager to create or delete rows in
the table, there must be a <CODE>RowStatus</CODE> column for
<CODE>is_set_ok</CODE>, <CODE>set</CODE> and <CODE>undo</CODE> to work properly.
<P>The function returns according to the specification of an
instrumentation function.
</DIV>
<P><A NAME="table_get_elements/3"><STRONG><CODE>table_get_elements(NameDb,RowIndex,Cols) -> Values</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Values = [term() | noinit]</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Returns a list with values for all columns in <CODE>Cols</CODE>.
If a column is undefined, its value is <CODE>noinit</CODE>.
</DIV>
<P><A NAME="table_next/2"><STRONG><CODE>table_next(NameDb,RestOid) -> RowIndex | endOfTable</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>RestOid = [int()]</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Finds the indices of the next row in the table. <CODE>RestOid</CODE>
does not have to specify an existing row.
</DIV>
<P><A NAME="table_row_exists/2"><STRONG><CODE>table_row_exists(NameDb,RowIndex) -> bool()</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Checks if a row in a table exists.
</DIV>
<P><A NAME="table_set_elements/3"><STRONG><CODE>table_set_elements(NameDb,RowIndex,Cols) -> bool()</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Sets the elements in <CODE>Cols</CODE> to the row specified by
<CODE>RowIndex</CODE>. No checks are performed on the new values.
<P>If the Mnesia database is used, this function calls
<CODE>mnesia:write</CODE> to store the values. This means that
this function must be called from within a transaction
(<CODE>mnesia:transaction/1</CODE> or <CODE>mnesia:dirty/1</CODE>).
</DIV>
<P><A NAME="variable_func/2"><STRONG><CODE>variable_func(Op1,NameDb)</CODE></STRONG></A><BR>
<A NAME="variable_func/3"><STRONG><CODE>variable_func(Op2,Val,NameDb) -> Ret</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Op1 = new | delete | get</CODE></STRONG><BR>
<STRONG><CODE>Op2 = is_set_ok | set | undo</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>This is the default instrumentation function for variables.
<P>The <CODE>new</CODE> function creates a new variable in the
database with a default value as defined in the MIB, or a zero
value (depending on the type). The <CODE>delete</CODE> function
does not delete the variable from the database. The function
returns according to the specification of an instrumentation
function.
</DIV>
<P><A NAME="variable_get/1"><STRONG><CODE>variable_get(NameDb) -> {value, Value} | undefined</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Value = term()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Gets the value of a variable.
</DIV>
<P><A NAME="variable_set/2"><STRONG><CODE>variable_set(NameDb,NewVal) -> true | false</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>NewVal = term()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Sets a new value to a variable. The variable is created if
it does not exist. No checks are made on the type of the
new value. Returns <CODE>false</CODE> if the <CODE>NameDb</CODE> argument
is incorrectly specified, otherwise <CODE>true</CODE>.
</DIV>
<H3>Example</H3>
<DIV CLASS=REFBODY>
<P>The following example shows an implementation of a table which is
stored in Mnesia, but with some checks performed at set-request
operations.
<PRE>
myTable_func(new, NameDb) -> % pass unchanged
snmp_generic:table_func(new, NameDb).
myTable_func(delete, NameDb) -> % pass unchanged
snmp_generic:table_func(delete, NameDb).
%% change row
myTable_func(is_set_ok, RowIndex, Cols, NameDb) ->
case snmp_generic:table_func(is_set_ok, RowIndex,
Cols, NameDb) of
{noError, 0} ->
myApplication:is_set_ok(RowIndex, Cols);
Err ->
Err
end;
myTable_func(set, RowIndex, Cols, NameDb) ->
case snmp_generic:table_func(set, RowIndex, Cols,
NameDb),
{noError, 0} ->
% Now the row is updated, tell the application
myApplication:update(RowIndex, Cols);
Err ->
Err
end;
myTable_func(Op, RowIndex, Cols, NameDb) -> % pass unchanged
snmp_generic:table_func(Op, RowIndex, Cols, NameDb).
</PRE>
<P>The <CODE>.funcs</CODE> file would look like:
<PRE>
{myTable, {myModule, myTable_func, [{myTable, mnesia}]}}.
</PRE>
</DIV>
<H3>AUTHORS</H3>
<DIV CLASS=REFBODY>
Martin Bjrklund - support@erlang.ericsson.se<BR>
Klas Eriksson - support@erlang.ericsson.se<BR>
</DIV>
<CENTER>
<HR>
<SMALL>snmp 4.8.2<BR>
Copyright © 1991-2006
<A HREF="http://www.erlang.se">Ericsson AB</A><BR>
</SMALL>
</CENTER>
</BODY>
</HTML>
|