~ubuntu-branches/debian/squeeze/erlang/squeeze

« back to all changes in this revision

Viewing changes to lib/snmp/src/agent/snmpa.erl

  • Committer: Bazaar Package Importer
  • Author(s): Erlang Packagers, Sergei Golovan
  • Date: 2006-12-03 17:07:44 UTC
  • mfrom: (2.1.11 feisty)
  • Revision ID: james.westby@ubuntu.com-20061203170744-rghjwupacqlzs6kv
Tags: 1:11.b.2-4
[ Sergei Golovan ]
Fixed erlang-base and erlang-base-hipe prerm scripts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
%% ``The contents of this file are subject to the Erlang Public License,
 
2
%% Version 1.1, (the "License"); you may not use this file except in
 
3
%% compliance with the License. You should have received a copy of the
 
4
%% Erlang Public License along with this software. If not, it can be
 
5
%% retrieved via the world wide web at http://www.erlang.org/.
 
6
%% 
 
7
%% Software distributed under the License is distributed on an "AS IS"
 
8
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 
9
%% the License for the specific language governing rights and limitations
 
10
%% under the License.
 
11
%% 
 
12
%% The Initial Developer of the Original Code is Ericsson Utvecklings AB.
 
13
%% Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings
 
14
%% AB. All Rights Reserved.''
 
15
%% 
 
16
%%     $Id$
 
17
%%
 
18
-module(snmpa).
 
19
 
 
20
 
 
21
%%----------------------------------------------------------------------
 
22
%% This module contains the user interface to the snmp agent toolkit.
 
23
%%----------------------------------------------------------------------
 
24
 
 
25
-export([verbosity/2, 
 
26
         
 
27
         current_request_id/0, current_community/0, current_address/0,
 
28
         current_context/0, current_net_if_data/0, 
 
29
         
 
30
         get_symbolic_store_db/0,
 
31
         which_aliasnames/0, 
 
32
         which_tables/0, 
 
33
         which_variables/0, 
 
34
         name_to_oid/1, name_to_oid/2, 
 
35
         oid_to_name/1, oid_to_name/2,
 
36
         int_to_enum/2, int_to_enum/3, 
 
37
         enum_to_int/2, enum_to_int/3,
 
38
 
 
39
         info/0, info/1, old_info_format/1, 
 
40
         load_mibs/1, load_mibs/2, 
 
41
         unload_mibs/1, unload_mibs/2, 
 
42
         which_mibs/0, which_mibs/1, 
 
43
         whereis_mib/1, whereis_mib/2, 
 
44
         dump_mibs/0, dump_mibs/1,
 
45
         mib_of/1, mib_of/2, 
 
46
         me_of/1,  me_of/2, 
 
47
 
 
48
         get/2, get/3, get_next/2, get_next/3,
 
49
 
 
50
         register_subagent/3, unregister_subagent/2, 
 
51
 
 
52
         send_notification/3, send_notification/4, send_notification/5,
 
53
         send_notification/6,
 
54
         send_trap/3, send_trap/4,
 
55
 
 
56
         register_notification_filter/3,
 
57
         register_notification_filter/4,
 
58
         register_notification_filter/5,
 
59
         unregister_notification_filter/1,
 
60
         unregister_notification_filter/2,
 
61
         which_notification_filter/0,
 
62
         which_notification_filter/1,
 
63
 
 
64
         sys_up_time/0, system_start_time/0,
 
65
 
 
66
         backup/1, backup/2, 
 
67
 
 
68
         convert_config/1]).
 
69
 
 
70
%% USM functions:
 
71
-export([passwd2localized_key/3, localize_key/3]).
 
72
 
 
73
%% Agent Capabilities functions
 
74
-export([add_agent_caps/2, del_agent_caps/1, get_agent_caps/0]).
 
75
 
 
76
%% Audit Trail Log functions
 
77
-export([log_to_txt/2, log_to_txt/3, log_to_txt/4, 
 
78
         log_to_txt/5, log_to_txt/6, log_to_txt/7, 
 
79
         change_log_size/1]).
 
80
 
 
81
 
 
82
-include("snmpa_atl.hrl").
 
83
 
 
84
 
 
85
%%-----------------------------------------------------------------
 
86
%% This utility function is used to convert an old SNMP application
 
87
%% config (prior to snmp-4.0) to a SNMP agent config (as of 
 
88
%% snmp-4.0).
 
89
%% This is the config structure of the SNMP application as of 
 
90
%% snmp-4.0:
 
91
%% {snmp, snmp_config()}
 
92
%% snmp_config() -> [snmp_config_item()]
 
93
%% snmp_config_item() -> {agent,   agent_config()} | 
 
94
%%                       {manager, manager_config()}
 
95
%%-----------------------------------------------------------------
 
96
 
 
97
convert_config(Opts) ->
 
98
    snmpa_app:convert_config(Opts).
 
99
 
 
100
 
 
101
%%-----------------------------------------------------------------
 
102
%% Note that verbosity for the agents is actually only implemented 
 
103
%% (properly) for the master agent.
 
104
%%-----------------------------------------------------------------
 
105
 
 
106
verbosity(all,Verbosity) -> 
 
107
    catch snmpa_agent:verbosity(sub_agents,Verbosity),
 
108
    catch snmpa_agent:verbosity(master_agent,Verbosity),
 
109
    catch snmpa_agent:verbosity(net_if,Verbosity),
 
110
    catch snmpa_agent:verbosity(mib_server,Verbosity),
 
111
    catch snmpa_agent:verbosity(note_store,Verbosity),
 
112
    catch snmpa_symbolic_store:verbosity(Verbosity),
 
113
    catch snmpa_local_db:verbosity(Verbosity);
 
114
verbosity(master_agent,Verbosity) -> 
 
115
    catch snmpa_agent:verbosity(master_agent,Verbosity);
 
116
verbosity(net_if,Verbosity) -> 
 
117
    catch snmpa_agent:verbosity(net_if,Verbosity);
 
118
verbosity(note_store,Verbosity) -> 
 
119
    catch snmpa_agent:verbosity(note_store, Verbosity);
 
120
verbosity(mib_server,Verbosity) -> 
 
121
    catch snmpa_agent:verbosity(mib_server,Verbosity);
 
122
verbosity(symbolic_store,Verbosity) -> 
 
123
    catch snmpa_symbolic_store:verbosity(Verbosity);
 
124
verbosity(local_db,Verbosity) -> 
 
125
    catch snmpa_local_db:verbosity(Verbosity);
 
126
verbosity(Agent,{subagents,Verbosity}) -> 
 
127
    catch snmpa_agent:verbosity(Agent,{sub_agents,Verbosity});
 
128
verbosity(Agent,Verbosity) -> 
 
129
    catch snmpa_agent:verbosity(Agent,Verbosity).
 
130
 
 
131
 
 
132
%%-----------------------------------------------------------------
 
133
%% 
 
134
%% Some symbolic store (internal database) utility functions
 
135
%% 
 
136
%%-----------------------------------------------------------------
 
137
 
 
138
get_symbolic_store_db() ->
 
139
    snmpa_symbolic_store:get_db().
 
140
 
 
141
 
 
142
which_aliasnames() ->
 
143
    snmpa_symbolic_store:which_aliasnames().
 
144
 
 
145
which_tables() ->
 
146
    snmpa_symbolic_store:which_tables().
 
147
 
 
148
which_variables() ->
 
149
    snmpa_symbolic_store:which_variables().
 
150
 
 
151
 
 
152
%%-----------------------------------------------------------------
 
153
%% These 8 functions returns {value, Val} | false
 
154
%%-----------------------------------------------------------------
 
155
name_to_oid(Name) ->
 
156
    snmpa_symbolic_store:aliasname_to_oid(Name).
 
157
 
 
158
name_to_oid(Db, Name) ->
 
159
    snmpa_symbolic_store:aliasname_to_oid(Db, Name).
 
160
 
 
161
oid_to_name(OID) ->
 
162
    snmpa_symbolic_store:oid_to_aliasname(OID).
 
163
 
 
164
oid_to_name(Db, OID) ->
 
165
    snmpa_symbolic_store:oid_to_aliasname(Db, OID).
 
166
 
 
167
enum_to_int(Name, Enum) ->
 
168
    snmpa_symbolic_store:enum_to_int(Name, Enum).
 
169
 
 
170
enum_to_int(Db, Name, Enum) ->
 
171
    snmpa_symbolic_store:enum_to_int(Db, Name, Enum).
 
172
 
 
173
int_to_enum(Name, Int) ->
 
174
    snmpa_symbolic_store:int_to_enum(Name, Int).
 
175
 
 
176
int_to_enum(Db, Name, Int) ->
 
177
    snmpa_symbolic_store:int_to_enum(Db, Name, Int).
 
178
 
 
179
 
 
180
%%-----------------------------------------------------------------
 
181
%% These functions must only be called in the process context
 
182
%% where the instrumentation functions are called!
 
183
%%-----------------------------------------------------------------
 
184
current_request_id()  -> current_get(snmp_request_id).
 
185
current_context()     -> current_get(snmp_context).
 
186
current_community()   -> current_get(snmp_community).
 
187
current_address()     -> current_get(snmp_address).
 
188
current_net_if_data() -> current_get(net_if_data).
 
189
 
 
190
current_get(Tag) ->
 
191
    case get(Tag) of
 
192
        undefined -> false;
 
193
        X -> {value, X}
 
194
    end.
 
195
    
 
196
 
 
197
%% -
 
198
 
 
199
get(Agent, Vars) -> snmpa_agent:get(Agent, Vars).
 
200
get(Agent, Vars, Context) -> snmpa_agent:get(Agent, Vars, Context).
 
201
 
 
202
get_next(Agent, Vars) -> snmpa_agent:get_next(Agent, Vars).
 
203
get_next(Agent, Vars, Context) -> snmpa_agent:get_next(Agent, Vars, Context).
 
204
 
 
205
 
 
206
info()      -> info(snmp_master_agent).
 
207
info(Agent) -> snmpa_agent:info(Agent).
 
208
 
 
209
old_info_format(Info) when list(Info) ->
 
210
    {value, Vsns}         = lists:keysearch(vsns,            1, Info),
 
211
    {value, {_, MibInfo}} = lists:keysearch(mib_server,      1, Info),
 
212
    {value, SAa}          = lists:keysearch(subagents,       1, MibInfo),
 
213
    {value, LoadedMibs}   = lists:keysearch(loaded_mibs,     1, MibInfo),
 
214
    {value, TreeSz}       = lists:keysearch(tree_size_bytes, 1, MibInfo),
 
215
    {value, ProcMem}      = lists:keysearch(process_memory,  1, MibInfo),
 
216
    {value, DbMem}        = lists:keysearch(db_memory,       1, MibInfo),
 
217
    [Vsns, SAa, LoadedMibs, TreeSz, ProcMem, DbMem].
 
218
    
 
219
 
 
220
%% -
 
221
 
 
222
backup(BackupDir) ->
 
223
    backup(snmp_master_agent, BackupDir).
 
224
 
 
225
backup(Agent, BackupDir) ->
 
226
    snmpa_agent:backup(Agent, BackupDir).
 
227
 
 
228
 
 
229
%% -
 
230
 
 
231
dump_mibs()     -> snmpa_agent:dump_mibs(snmp_master_agent).
 
232
dump_mibs(File) -> snmpa_agent:dump_mibs(snmp_master_agent, File).
 
233
 
 
234
load_mibs(Mibs) ->
 
235
    load_mibs(snmp_master_agent, Mibs).
 
236
load_mibs(Agent, Mibs) when list(Mibs) -> 
 
237
    snmpa_agent:load_mibs(Agent, Mibs).
 
238
 
 
239
unload_mibs(Mibs) ->
 
240
    unload_mibs(snmp_master_agent, Mibs).
 
241
unload_mibs(Agent, Mibs) when list(Mibs) -> 
 
242
    snmpa_agent:unload_mibs(Agent, Mibs).
 
243
 
 
244
which_mibs()      -> which_mibs(snmp_master_agent).
 
245
which_mibs(Agent) -> snmpa_agent:which_mibs(Agent).
 
246
 
 
247
whereis_mib(Mib) ->
 
248
    whereis_mib(snmp_master_agent, Mib).
 
249
whereis_mib(Agent, Mib) when atom(Mib) ->
 
250
    snmpa_agent:whereis_mib(Agent, Mib).
 
251
 
 
252
 
 
253
%% -
 
254
 
 
255
mib_of(Oid) ->
 
256
    snmpa_agent:mib_of(Oid).
 
257
 
 
258
mib_of(Agent, Oid) ->
 
259
    snmpa_agent:mib_of(Agent, Oid).
 
260
 
 
261
me_of(Oid) ->
 
262
    snmpa_agent:me_of(Oid).
 
263
 
 
264
me_of(Agent, Oid) ->
 
265
    snmpa_agent:me_of(Agent, Oid).
 
266
 
 
267
 
 
268
%% -
 
269
 
 
270
register_notification_filter(Id, Mod, Data) when atom(Mod) ->
 
271
    register_notification_filter(snmp_master_agent, Id, Mod, Data, last).
 
272
 
 
273
register_notification_filter(Agent, Id, Mod, Data)
 
274
  when atom(Agent), atom(Mod) ->
 
275
    register_notification_filter(Agent, Id, Mod, Data, last);
 
276
register_notification_filter(Agent, Id, Mod, Data)
 
277
  when pid(Agent), atom(Mod) ->
 
278
    register_notification_filter(Agent, Id, Mod, Data, last);
 
279
register_notification_filter(Id, Mod, Data, Where) when atom(Mod) ->
 
280
    register_notification_filter(snmp_master_agent, Id, Mod, Data, Where).
 
281
 
 
282
register_notification_filter(Agent, Id, Mod, Data, Where) ->
 
283
    snmpa_agent:register_notification_filter(Agent, Id, Mod, Data, Where).
 
284
 
 
285
unregister_notification_filter(Id) ->
 
286
    unregister_notification_filter(snmp_master_agent, Id).
 
287
 
 
288
unregister_notification_filter(Agent, Id) ->
 
289
    snmpa_agent:unregister_notification_filter(Agent, Id).
 
290
 
 
291
which_notification_filter() ->
 
292
    which_notification_filter(snmp_master_agent).
 
293
 
 
294
which_notification_filter(Agent) ->
 
295
    snmpa_agent:which_notification_filter(Agent).
 
296
 
 
297
 
 
298
%% -
 
299
 
 
300
send_notification(Agent, Notification, Recv) ->
 
301
    send_notification(Agent, Notification, Recv, "", "", []).
 
302
 
 
303
send_notification(Agent, Notification, Recv, Varbinds) ->
 
304
    send_notification(Agent, Notification, Recv, "", "", Varbinds).
 
305
 
 
306
send_notification(Agent, Notification, Recv, NotifyName, Varbinds) ->
 
307
    send_notification(Agent, Notification, Recv, NotifyName, "", Varbinds).
 
308
 
 
309
send_notification(Agent, Notification, Recv,NotifyName,ContextName,Varbinds) 
 
310
  when list(NotifyName), list(ContextName), list(Varbinds) ->
 
311
    snmpa_agent:send_trap(Agent, Notification, NotifyName, 
 
312
                          ContextName, Recv, Varbinds).
 
313
 
 
314
%% Kept for backwards compatibility
 
315
send_trap(Agent, Trap, Community) ->
 
316
    send_notification(Agent, Trap, no_receiver, Community, "", []).
 
317
 
 
318
send_trap(Agent, Trap, Community, Varbinds) ->
 
319
    send_notification(Agent, Trap, no_receiver, Community, "", Varbinds).
 
320
 
 
321
register_subagent(Agent, SubTree, SubAgent) ->
 
322
    snmpa_agent:register_subagent(Agent, SubTree, SubAgent).
 
323
 
 
324
unregister_subagent(Agent, SubOidOrPid) ->
 
325
    snmpa_agent:unregister_subagent(Agent, SubOidOrPid).
 
326
 
 
327
system_start_time() ->
 
328
    [{_, Time}] = ets:lookup(snmp_agent_table, system_start_time),
 
329
    Time.
 
330
 
 
331
sys_up_time() ->
 
332
    % time in 0.01 seconds.
 
333
    StartTime = system_start_time(),
 
334
    (snmp_misc:now(cs) - StartTime) rem (2 bsl 31).
 
335
 
 
336
 
 
337
%%%-----------------------------------------------------------------
 
338
%%% USM functions
 
339
%%%-----------------------------------------------------------------
 
340
passwd2localized_key(Alg, Passwd, EngineID) ->
 
341
    snmp_usm:passwd2localized_key(Alg, Passwd, EngineID).
 
342
 
 
343
localize_key(Alg, Key, EngineID) ->
 
344
    snmp_usm:localize_key(Alg, Key, EngineID).
 
345
 
 
346
 
 
347
%%%-----------------------------------------------------------------
 
348
%%% Agent Capabilities functions
 
349
%%%-----------------------------------------------------------------
 
350
add_agent_caps(Oid, Descr) ->
 
351
    snmp_standard_mib:add_agent_caps(Oid, Descr).
 
352
 
 
353
del_agent_caps(Index) ->
 
354
    snmp_standard_mib:del_agent_caps(Index).
 
355
 
 
356
get_agent_caps() ->
 
357
    snmp_standard_mib:get_agent_caps().
 
358
 
 
359
 
 
360
%%%-----------------------------------------------------------------
 
361
%%% Audit Trail Log functions 
 
362
%%%-----------------------------------------------------------------
 
363
log_to_txt(LogDir, Mibs) -> 
 
364
    OutFile = "snmpa_log.txt",       
 
365
    LogName = ?audit_trail_log_name, 
 
366
    LogFile = ?audit_trail_log_file, 
 
367
    snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile).
 
368
log_to_txt(LogDir, Mibs, OutFile) -> 
 
369
    LogName = ?audit_trail_log_name, 
 
370
    LogFile = ?audit_trail_log_file, 
 
371
    snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile).
 
372
log_to_txt(LogDir, Mibs, OutFile, LogName) -> 
 
373
    LogFile = ?audit_trail_log_file, 
 
374
    snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile).
 
375
log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile) -> 
 
376
    snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile).
 
377
log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Start) -> 
 
378
    snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Start).
 
379
log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Start, Stop) -> 
 
380
    snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Start, Stop).
 
381
 
 
382
 
 
383
change_log_size(NewSize) -> 
 
384
    LogName = ?audit_trail_log_name, % The old (agent) default
 
385
    snmp:change_log_size(LogName, NewSize).
 
386
 
 
387