-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
snmpa.erl
2797 lines (2305 loc) · 88.2 KB
/
snmpa.erl
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
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 2004-2024. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
%%
%% %CopyrightEnd%
%%
-module(snmpa).
-moduledoc """
Interface Functions to the SNMP toolkit agent
The module `snmpa` contains interface functions to the SNMP agent.
""".
%%----------------------------------------------------------------------
%% This module contains the user interface to the snmp agent toolkit.
%%----------------------------------------------------------------------
-export([verbosity/2,
current_request_id/0, current_community/0, current_address/0,
current_context/0, current_net_if_data/0,
get_symbolic_store_db/0,
which_aliasnames/0,
which_tables/0,
which_variables/0,
which_notifications/0,
name_to_oid/1, name_to_oid/2,
oid_to_name/1, oid_to_name/2,
int_to_enum/2, int_to_enum/3,
enum_to_int/2, enum_to_int/3,
name_db/1,
info/0, info/1,
load_mib/1, load_mib/2,
load_mibs/1, load_mibs/2, load_mibs/3,
unload_mib/1, unload_mib/2,
unload_mibs/1, unload_mibs/2, unload_mibs/3,
which_mibs/0, which_mibs/1,
whereis_mib/1, whereis_mib/2,
dump_mibs/0, dump_mibs/1,
mib_of/1, mib_of/2,
me_of/1, me_of/2,
invalidate_mibs_cache/0, invalidate_mibs_cache/1,
which_mibs_cache_size/0, which_mibs_cache_size/1,
enable_mibs_cache/0, enable_mibs_cache/1,
disable_mibs_cache/0, disable_mibs_cache/1,
gc_mibs_cache/0, gc_mibs_cache/1, gc_mibs_cache/2, gc_mibs_cache/3,
enable_mibs_cache_autogc/0, enable_mibs_cache_autogc/1,
disable_mibs_cache_autogc/0, disable_mibs_cache_autogc/1,
update_mibs_cache_age/1, update_mibs_cache_age/2,
update_mibs_cache_gclimit/1, update_mibs_cache_gclimit/2,
get/2, get/3, get_next/2, get_next/3,
register_subagent/3, unregister_subagent/2,
which_transports/0,
send_notification2/3,
send_notification/3, send_notification/4, send_notification/5,
send_notification/6, send_notification/7,
send_trap/3, send_trap/4,
discovery/2, discovery/3, discovery/4, discovery/5, discovery/6,
sys_up_time/0, system_start_time/0,
backup/1, backup/2,
convert_config/1,
restart_worker/0, restart_worker/1,
restart_set_worker/0, restart_set_worker/1]).
%% USM functions:
-export([passwd2localized_key/3, localize_key/3]).
%% Agent Capabilities functions
-export([add_agent_caps/2, del_agent_caps/1, get_agent_caps/0]).
%% Audit Trail Log functions
-export([log_to_txt/1, log_to_txt/2, log_to_txt/3, log_to_txt/4,
log_to_txt/5, log_to_txt/6, log_to_txt/7, log_to_txt/8,
log_to_io/1, log_to_io/2, log_to_io/3, log_to_io/4,
log_to_io/5, log_to_io/6, log_to_io/7,
log_info/0,
change_log_size/1,
get_log_type/0, get_log_type/1,
change_log_type/1, change_log_type/2,
set_log_type/1, set_log_type/2
]).
%% Message filter / load regulation functions
-export([
register_notification_filter/3,
register_notification_filter/4,
register_notification_filter/5,
unregister_notification_filter/1,
unregister_notification_filter/2,
which_notification_filter/0,
which_notification_filter/1,
get_request_limit/0, get_request_limit/1,
set_request_limit/1, set_request_limit/2
]).
-export([print_mib_info/0, print_mib_tables/0, print_mib_variables/0]).
-export_type([
me/0,
table_name/0,
variable_name/0,
name/0,
db/0,
name_db/0,
pdu_type/0,
discovery_handler/0,
%% Agent config types
mib_storage/0,
mib_storage_opt/0,
mib_storage_module/0,
mib_storage_options/0,
nfilter_id/0,
nfilter_position/0,
notification_delivery_info/0,
transport_kind/0
]).
-include("snmpa_atl.hrl").
-include("snmpa_internal.hrl").
-include_lib("snmp/include/snmp_types.hrl"). % type of me needed.
-define(DISCO_EXTRA_INFO, undefined).
-define(ATL_BLOCK_DEFAULT, true).
%%-----------------------------------------------------------------
%% Types
%%-----------------------------------------------------------------
-type me() :: snmp:me().
-doc """
Module implementing the [snmpa_discovery_handler](`m:snmpa_discovery_handler#`)
behaviour.
""".
-type discovery_handler() :: module().
%% Agent config types
-type mib_storage() :: [mib_storage_opt()].
-type mib_storage_opt() :: {module, mib_storage_module()} |
{options, mib_storage_options()}.
%% Module implementing the snmpa_mib_storage behaviour
-type mib_storage_module() :: atom().
%% Options specific to the above module
-type mib_storage_options() :: list().
-type table_name() :: atom().
-type variable_name() :: atom().
-type name() :: table_name() | variable_name().
-type db() :: volatile | persistent | mnesia.
-type name_db() :: {name(), db()}.
-type mib_module() :: atom().
-type mib_info() :: {mib_module(), [table_name()], [variable_name()]}.
-type pdu_type() :: snmp:pdu_type().
-type nfilter_id() :: term().
-type nfilter_position() :: first | last |
{insert_before, nfilter_id()} |
{insert_after, nfilter_id()}.
-doc "How shall (notification) delivery info be reported.".
-type notification_delivery_info() ::
snmpa_notification_delivery_info_receiver:notification_delivery_info().
-type transport_kind() :: req_responder | trap_sender.
%%-----------------------------------------------------------------
-doc false.
-spec name_db(Name) -> NameDb when
Name :: name(),
NameDb :: name_db().
name_db(Name) ->
snmpa_agent:db(Name).
%%-----------------------------------------------------------------
%% This utility function is used to convert an old SNMP application
%% config (prior to snmp-4.0) to a SNMP agent config (as of
%% snmp-4.0).
%% This is the config structure of the SNMP application as of
%% snmp-4.0:
%% {snmp, snmp_config()}
%% snmp_config() -> [snmp_config_item()]
%% snmp_config_item() -> {agent, agent_config()} |
%% {manager, manager_config()}
%%-----------------------------------------------------------------
-doc """
This off-line utility function can be used to convert the old snmp application
config (pre snmp-4.0) to the new snmp agent config (as of snmp-4.0).
For information about the old config (`OldConfig`) see the OTP R9C
documentation.
For information about the current agent config (`AgentConfig`), see the
[Configuring the application](snmp_config.md#configuration_params) chapter of
the SNMP user's guide.
""".
-spec convert_config(OldConfig) -> NewConfig when
OldConfig :: list(),
NewConfig :: list().
convert_config(Opts) ->
snmpa_app:convert_config(Opts).
%%-----------------------------------------------------------------
%% Note that verbosity for the agents is actually only implemented
%% (properly) for the master agent.
%%-----------------------------------------------------------------
-doc """
Sets 'verbosity' for the indicated process(s):
- **`all`** -
Sets verbosity for all the agent processes; net_if, note_store, mib_server,
symbolic_store, local_db and master_agent (and sub-agents).
- **`net_if`** - Sets verbosity for the net-if process.
- **`note_store`** - Sets verbosity for the note store process.
- **`mib_server`** - Sets verbosity for the mib server process.
- **`symbolic_store`** - Sets verbosity for the symbolic store process.
- **`local_db`** - Sets verbosity for the local-db process.
- **`master_agent | pid()`** when `Verbosity = {subagents,` [`snmp:verbosity()`](`t:snmp:verbosity/0`)`}` -
Sets verbosity for all sub-agent(s) controlled by this (master) agent.
- **`master_agent | pid()`** - Sets verbosity for the agent process.
""".
-spec verbosity(Target, Verbosity) -> snmp:void() when
Target :: all,
Verbosity :: snmp:verbosity();
(Target, Verbosity) -> snmp:void() when
Target :: net_if,
Verbosity :: snmp:verbosity();
(Target, Verbosity) -> snmp:void() when
Target :: note_store,
Verbosity :: snmp:verbosity();
(Target, Verbosity) -> snmp:void() when
Target :: mib_server,
Verbosity :: snmp:verbosity();
(Target, Verbosity) -> snmp:void() when
Target :: symbolic_store,
Verbosity :: snmp:verbosity();
(Target, Verbosity) -> snmp:void() when
Target :: local_db,
Verbosity :: snmp:verbosity();
(Target, Verbosity) -> snmp:void() when
Target :: master_agent | Agent,
Agent :: pid() | AgentName,
AgentName :: atom(),
Verbosity :: {subagents, snmp:verbosity()};
(Agent, Verbosity) -> snmp:void() when
Agent :: pid() | AgentName,
AgentName :: atom(),
Verbosity :: snmp:verbosity().
verbosity(all = _Target, Verbosity) when is_atom(Verbosity) ->
catch snmpa_agent:verbosity(sub_agents, Verbosity),
catch snmpa_agent:verbosity(master_agent, Verbosity),
catch snmpa_agent:verbosity(net_if, Verbosity),
catch snmpa_agent:verbosity(mib_server, Verbosity),
catch snmpa_agent:verbosity(note_store, Verbosity),
catch snmpa_symbolic_store:verbosity(Verbosity),
catch snmpa_local_db:verbosity(Verbosity);
verbosity(net_if = Target, Verbosity) when is_atom(Verbosity) ->
catch snmpa_agent:verbosity(Target, Verbosity);
verbosity(note_store = Target, Verbosity) when is_atom(Verbosity) ->
catch snmpa_agent:verbosity(Target, Verbosity);
verbosity(mib_server = Target, Verbosity) when is_atom(Verbosity) ->
catch snmpa_agent:verbosity(Target,Verbosity);
verbosity(symbolic_store = _Target, Verbosity) when is_atom(Verbosity) ->
catch snmpa_symbolic_store:verbosity(Verbosity);
verbosity(local_db = _Target, Verbosity) when is_atom(Verbosity) ->
catch snmpa_local_db:verbosity(Verbosity);
verbosity(Target, {subagents, Verbosity})
when ((Target =:= master_agent) orelse
is_pid(Target) orelse
is_atom(Target)) andalso
is_atom(Verbosity) ->
catch snmpa_agent:verbosity(Target, {sub_agents, Verbosity});
verbosity(Target, Verbosity)
when (is_pid(Target) orelse is_atom(Target)) andalso
is_atom(Verbosity) ->
catch snmpa_agent:verbosity(Target, Verbosity).
%%-----------------------------------------------------------------
%%
%% Some symbolic store (internal database) utility functions
%%
%%-----------------------------------------------------------------
-doc false.
get_symbolic_store_db() ->
snmpa_symbolic_store:get_db().
-doc """
Retrieve all alias-names known to the agent.
""".
-spec which_aliasnames() -> AliasNames when
AliasNames :: [AliasName],
AliasName :: atom().
which_aliasnames() ->
snmpa_symbolic_store:which_aliasnames().
-doc """
Retrieve all tables known to the agent.
""".
-spec which_tables() -> Tables when
Tables :: [Table],
Table :: atom().
which_tables() ->
snmpa_symbolic_store:which_tables().
-doc """
Retrieve all variables known to the agent.
""".
-spec which_variables() -> Variables when
Variables :: [Variable],
Variable :: atom().
which_variables() ->
snmpa_symbolic_store:which_variables().
-doc """
Retrieve all notifications (and traps) known to the agent.
""".
-spec which_notifications() -> Notifications when
Notifications :: [{Name, MibName, Info}],
Name :: atom(),
MibName :: atom(),
Info :: term().
which_notifications() ->
snmpa_symbolic_store:which_notifications().
%%-----------------------------------------------------------------
%% These 8 functions returns {value, Val} | false
%%-----------------------------------------------------------------
-doc(#{equiv => name_to_oid/2}).
-spec name_to_oid(Name) -> {value, Oid} | false when
Name :: atom(),
Oid :: snmp:oid().
name_to_oid(Name) ->
snmpa_symbolic_store:aliasname_to_oid(Name).
-doc """
Looks up the OBJECT IDENTIFIER of a MIB object, given the symbolic name. Note,
the OBJECT IDENTIFIER is given for the object, not for an instance.
`false` is returned if the object is not defined in any loaded MIB.
`Db` is a reference to the symbolic store database (retrieved by a call to
`get_symbolic_store_db/0`).
""".
-spec name_to_oid(Db, Name) -> {value, Oid} | false when
Db :: term(),
Name :: atom(),
Oid :: snmp:oid().
name_to_oid(Db, Name) ->
snmpa_symbolic_store:aliasname_to_oid(Db, Name).
-doc(#{equiv => oid_to_name/2}).
-spec oid_to_name(Oid) -> {value, Name} | false when
Oid :: snmp:oid(),
Name :: atom().
oid_to_name(Oid) ->
snmpa_symbolic_store:oid_to_aliasname(Oid).
-doc """
Looks up the symbolic name of a MIB object, given OBJECT IDENTIFIER.
`false` is returned if the object is not defined in any loaded MIB.
`Db` is a reference to the symbolic store database (retrieved by a call to
`get_symbolic_store_db/0`).
""".
-spec oid_to_name(Db, Oid) -> {value, Name} | false when
Db :: term(),
Oid :: snmp:oid(),
Name :: atom().
oid_to_name(Db, Oid) ->
snmpa_symbolic_store:oid_to_aliasname(Db, Oid).
-doc(#{equiv => enum_to_int/3}).
-spec enum_to_int(Name, Enum) -> {value, Int} | false when
Name :: atom(),
Enum :: atom(),
Int :: integer().
enum_to_int(Name, Enum) ->
snmpa_symbolic_store:enum_to_int(Name, Enum).
-doc """
Converts the symbolic value `Enum` to the corresponding integer of the
enumerated object or type `Name` in a MIB. The MIB must be loaded.
`false` is returned if the object or type is not defined in any loaded MIB, or
if it does not define the symbolic value as enumerated.
`Db` is a reference to the symbolic store database (retrieved by a call to
`get_symbolic_store_db/0`).
""".
-spec enum_to_int(Db, Name, Enum) -> {value, Int} | false when
Db :: term(),
Name :: atom(),
Enum :: atom(),
Int :: integer().
enum_to_int(Db, Name, Enum) ->
snmpa_symbolic_store:enum_to_int(Db, Name, Enum).
-doc(#{equiv => int_to_enum/3}).
-spec int_to_enum(Name, Int) -> {value, Enum} | false when
Name :: atom(),
Int :: integer(),
Enum :: atom().
int_to_enum(Name, Int) ->
snmpa_symbolic_store:int_to_enum(Name, Int).
-doc """
Converts the integer `Int` to the corresponding symbolic value of the enumerated
object or type `Name` in a MIB. The MIB must be loaded.
`false` is returned if the object or type is not defined in any loaded MIB, or
if it does not define the symbolic value as enumerated.
`Db` is a reference to the symbolic store database (retrieved by a call to
`get_symbolic_store_db/0`).
""".
-spec int_to_enum(Db, Name, Int) -> {value, Enum} | false when
Db :: term(),
Name :: atom(),
Int :: integer(),
Enum :: atom().
int_to_enum(Db, Name, Int) ->
snmpa_symbolic_store:int_to_enum(Db, Name, Int).
%%-----------------------------------------------------------------
%% These functions must only be called in the process context
%% where the instrumentation functions are called!
%%-----------------------------------------------------------------
-doc """
Get the address of the request currently being processed by the agent.
Note that this function is intended to be called by the instrumentation
functions and _only_ if it is executed in the context of the agent process (e.g.
it _does not work_ if called from a spawned process).
""".
-spec current_address() -> {value, Address} | false when
Address :: term().
current_address() -> current_get(snmp_address).
-doc """
Get the community of the request currently being processed by the agent.
Note that this function is intended to be called by the instrumentation
functions and _only_ if it is executed in the context of the agent process (e.g.
it _does not work_ if called from a spawned process).
""".
-spec current_community() -> {value, Community} | false when
Community :: snmp_community_mib:name().
current_community() -> current_get(snmp_community).
-doc """
Get the context of the request currently being processed by the agent.
Note that this function is intended to be called by the instrumentation
functions and _only_ if it is executed in the context of the agent process (e.g.
it _does not work_ if called from a spawned process).
""".
-spec current_context() -> {value, Context} | false when
Context :: snmp_community_mib:context_name().
current_context() -> current_get(snmp_context).
-doc """
Get the request-id of the request currently being processed by the agent.
Note that this function is intended to be called by the instrumentation
functions and _only_ if it is executed in the context of the agent process (e.g.
it _does not work_ if called from a spawned process).
""".
-spec current_request_id() -> {value, RequestId} | false when
RequestId :: integer().
current_request_id() -> current_get(snmp_request_id).
-doc false.
current_net_if_data() -> current_get(net_if_data).
current_get(Tag) ->
case get(Tag) of
undefined -> false;
X -> {value, X}
end.
%% -
-doc(#{equiv => get/3}).
-spec get(Agent, Vars) -> Values | {error, Reason} when
Agent :: pid() | AgentName,
AgentName :: atom(),
Vars :: [snmp:oid()],
Values :: [term()],
Reason :: term().
get(Agent, Vars) -> snmpa_agent:get(Agent, Vars).
-doc """
Performs a GET operation on the agent. All loaded MIB objects are visible in
this operation. The agent calls the corresponding instrumentation functions just
as if it was a GET request coming from a manager.
Note that the request specific parameters (such as
`current_request_id/0`) are not accessible for the
instrumentation functions if this function is used.
""".
-spec get(Agent, Vars, Context) -> Values | {error, Reason} when
Agent :: pid() | AgentName,
AgentName :: atom(),
Vars :: [snmp:oid()],
Context :: snmp_community_mib:context_name(),
Values :: [term()],
Reason :: term().
get(Agent, Vars, Context) -> snmpa_agent:get(Agent, Vars, Context).
-doc(#{equiv => get_next/3}).
-spec get_next(Agent, Vars) -> Values | {error, Reason} when
Agent :: pid() | AgentName,
AgentName :: atom(),
Vars :: [snmp:oid()],
Values :: [{snmp:oid(), term()}],
Reason :: term().
get_next(Agent, Vars) -> snmpa_agent:get_next(Agent, Vars).
-doc """
Performs a GET-NEXT operation on the agent. All loaded MIB objects are visible
in this operation. The agent calls the corresponding instrumentation functions
just as if it was a GET request coming from a manager.
Note that the request specific parameters (such as `snmpa:current_request_id/0`
are not accessible for the instrumentation functions if this function is used.
""".
-spec get_next(Agent, Vars, Context) -> Values | {error, Reason} when
Agent :: pid() | AgentName,
AgentName :: atom(),
Vars :: [snmp:oid()],
Context :: snmp_community_mib:context_name(),
Values :: [{snmp:oid(), term()}],
Reason :: {atom(), snmp:oid()}.
get_next(Agent, Vars, Context) -> snmpa_agent:get_next(Agent, Vars, Context).
-doc(#{equiv => info/1}).
-spec info() -> Info when
Info :: [{Key, Value}],
Key :: term(),
Value :: term().
info() -> info(snmp_master_agent).
-doc """
Returns a list (a dictionary) containing information about the agent.
Information includes loaded MIBs, registered sub-agents, some information about
the memory allocation.
""".
-spec info(Agent) -> Info when
Agent :: pid() | AgentName,
AgentName :: atom(),
Info :: [{Key, Value}],
Key :: term(),
Value :: term().
info(Agent) -> snmpa_agent:info(Agent).
%% -
-doc(#{equiv => backup/2}).
-spec backup(BackupDir) -> ok | {error, Reason} when
BackupDir :: string(),
Reason :: backup_in_progress | term().
backup(BackupDir) ->
backup(snmp_master_agent, BackupDir).
-doc """
Backup persistent/permanent data handled by the agent (such as local-db,
mib-data and vacm).
Data stored by mnesia is not handled.
`BackupDir` cannot be identical to DbDir.
Simultaneous backup calls are _not_ allowed. That is, two different processes
cannot simultaneously successfully call this function. One of them will be
first, and succeed. The second will fail with the error reason
`backup_in_progress`.
""".
-spec backup(Agent, BackupDir) -> ok | {error, Reason} when
Agent :: pid() | AgentName,
AgentName :: atom(),
BackupDir :: string(),
Reason :: backup_in_progress | term().
backup(Agent, BackupDir) ->
snmpa_agent:backup(Agent, BackupDir).
%% -
-doc false.
dump_mibs() -> snmpa_agent:dump_mibs(snmp_master_agent).
-doc false.
dump_mibs(File) -> snmpa_agent:dump_mibs(snmp_master_agent, File).
-doc(#{equiv => load_mib/2}).
-doc(#{since => <<"OTP R16B02">>}).
-spec load_mib(Mib) ->
ok | {error, Reason} when
Mib :: string(),
Reason :: already_loaded | term().
load_mib(Mib) ->
load_mib(snmp_master_agent, Mib).
-doc """
Load a single `Mib` into an agent. The `MibName` is the name of the Mib,
including the path to where the compiled mib is found. For example:
```erlang
Dir = code:priv_dir(my_app) ++ "/mibs/",
snmpa:load_mib(snmp_master_agent, Dir ++ "MY-MIB").
```
""".
-doc(#{since => <<"OTP R16B02">>}).
-spec load_mib(Agent, Mib) ->
ok | {error, Reason} when
Agent :: pid() | AgentName,
AgentName :: atom(),
Mib :: string(),
Reason :: already_loaded | term().
load_mib(Agent, Mib) ->
case load_mibs(Agent, [Mib]) of
{error, {'load aborted at', Mib, Reason}} ->
{error, Reason};
Else ->
Else
end.
-doc(#{equiv => load_mibs/3}).
-spec load_mibs(Mibs) ->
ok | {error, Reason} when
Mibs :: [MibName],
MibName :: string(),
Reason :: {'load aborted at', MibName, InternalReason},
InternalReason :: already_loaded | term().
load_mibs(Mibs) ->
load_mibs(snmp_master_agent, Mibs, false).
-doc(#{equiv => load_mibs/3}).
-spec load_mibs(Agent, Mibs) -> ok | {error, Reason} when
Agent :: pid() | AgentName,
AgentName :: atom(),
Mibs :: [MibName],
MibName :: string(),
Reason :: {'load aborted at', MibName, InternalReason},
InternalReason :: already_loaded | term();
(Mibs, Force) -> ok | {error, Reason} when
Mibs :: [MibName],
MibName :: string(),
Force :: boolean(),
Reason :: {'load aborted at', MibName, InternalReason},
InternalReason :: already_loaded | term().
load_mibs(Agent, Mibs) when is_list(Mibs) ->
snmpa_agent:load_mibs(Agent, Mibs, false);
load_mibs(Mibs, Force)
when is_list(Mibs) andalso is_boolean(Force) ->
load_mibs(snmp_master_agent, Mibs, Force).
-doc """
Load `Mibs` into an agent. If the agent cannot load all MIBs (the default value
of the `Force` argument is `false`), it will indicate where loading was aborted.
The `MibName` is the name of the Mib, including the path to where the compiled
mib is found. For example,
```erlang
Dir = code:priv_dir(my_app) ++ "/mibs/",
snmpa:load_mibs(snmp_master_agent, [Dir ++ "MY-MIB"]).
```
If `Force = true` then the agent will continue attempting to load each mib even
after failing to load a previous mib. Use with care.
""".
-doc(#{since => <<"OTP R16B02">>}).
-spec load_mibs(Agent, Mibs, Force) -> ok | {error, Reason} when
Agent :: pid() | AgentName,
AgentName :: atom(),
Mibs :: [MibName],
MibName :: string(),
Force :: boolean(),
Reason :: {'load aborted at', MibName, InternalReason},
InternalReason :: already_loaded | term().
load_mibs(Agent, Mibs, Force)
when is_list(Mibs) andalso is_boolean(Force) ->
snmpa_agent:load_mibs(Agent, Mibs, Force).
-doc(#{equiv => unload_mib/2}).
-doc(#{since => <<"OTP R16B02">>}).
-spec unload_mib(Mib) ->
ok | {error, Reason} when
Mib :: string(),
Reason :: not_loaded | term().
unload_mib(Mib) ->
unload_mib(snmp_master_agent, Mib).
-doc """
Unload a single `Mib` from an agent.
""".
-doc(#{since => <<"OTP R16B02">>}).
-spec unload_mib(Agent, Mib) ->
ok | {error, Reason} when
Agent :: pid() | AgentName,
AgentName :: atom(),
Mib :: string(),
Reason :: not_loaded | term().
unload_mib(Agent, Mib) ->
case unload_mibs(Agent, [Mib]) of
{error, {'unload aborted at', Mib, Reason}} ->
{error, Reason};
Else ->
Else
end.
-doc(#{equiv => unload_mibs/3}).
-spec unload_mibs(Mibs) ->
ok | {error, Reason} when
Mibs :: [MibName],
MibName :: string(),
Reason :: {'unload aborted at', MibName, InternalReason},
InternalReason :: not_loaded | term().
unload_mibs(Mibs) ->
unload_mibs(snmp_master_agent, Mibs).
-doc(#{equiv => unload_mibs/3}).
-spec unload_mibs(Agent, Mibs) ->
ok | {error, Reason} when
Agent :: pid() | AgentName,
AgentName :: atom(),
Mibs :: [MibName],
MibName :: string(),
Reason :: {'unload aborted at', MibName, InternalReason},
InternalReason :: not_loaded | term();
(Mibs, Force) ->
ok | {error, Reason} when
Mibs :: [MibName],
MibName :: string(),
Force :: boolean(),
Reason :: {'unload aborted at', MibName, InternalReason},
InternalReason :: not_loaded | term().
unload_mibs(Agent, Mibs) when is_list(Mibs) ->
unload_mibs(Agent, Mibs, false);
unload_mibs(Mibs, Force)
when is_list(Mibs) andalso is_boolean(Force) ->
unload_mibs(snmp_master_agent, Mibs, Force).
-doc """
Unload `Mibs` from an agent. If it cannot unload all MIBs (the default value of
the `Force` argument is `false`), it will indicate where unloading was aborted.
If `Force = true` then the agent will continue attempting to unload each mib
even after failing to unload a previous mib. Use with care.
""".
-doc(#{since => <<"OTP R16B02">>}).
-spec unload_mibs(Agent, Mibs, Force) ->
ok | {error, Reason} when
Agent :: pid() | AgentName,
AgentName :: atom(),
Mibs :: [MibName],
MibName :: string(),
Force :: boolean(),
Reason :: {'unload aborted at', MibName, InternalReason},
InternalReason :: not_loaded | term().
unload_mibs(Agent, Mibs, Force)
when is_list(Mibs) andalso is_boolean(Force) ->
snmpa_agent:unload_mibs(Agent, Mibs, Force).
-doc(#{equiv => which_mibs/1}).
-spec which_mibs() -> Mibs when
Mibs :: [{MibName, MibFile}],
MibName :: atom(),
MibFile :: string().
which_mibs() -> which_mibs(snmp_master_agent).
-doc """
Retrieve the list of all the mibs loaded into this agent. Default is the master
agent.
""".
-spec which_mibs(Agent) -> Mibs when
Agent :: pid() | AgentName,
AgentName :: atom(),
Mibs :: [{MibName, MibFile}],
MibName :: atom(),
MibFile :: string().
which_mibs(Agent) -> snmpa_agent:which_mibs(Agent).
-doc(#{equiv => whereis_mib/2}).
-spec whereis_mib(MibName) -> {ok, MibFile} | {error, Reason} when
MibName :: atom(),
MibFile :: string(),
Reason :: term().
whereis_mib(Mib) ->
whereis_mib(snmp_master_agent, Mib).
-doc """
Get the full path to the (compiled) mib-file.
""".
-spec whereis_mib(Agent, MibName) -> {ok, MibFile} | {error, Reason} when
Agent :: pid() | AgentName,
AgentName :: atom(),
MibName :: atom(),
MibFile :: string(),
Reason :: term().
whereis_mib(Agent, MibName) when is_atom(MibName) ->
snmpa_agent:whereis_mib(Agent, MibName).
%% -
-spec mibs_info() -> [mib_info()].
mibs_info() ->
[
{snmp_standard_mib,
[],
[
sysDescr,
sysObjectID,
sysContact,
sysName,
sysLocation,
sysServices,
snmpEnableAuthenTraps,
sysUpTime,
snmpInPkts,
snmpOutPkts,
snmpInBadVersions,
snmpInBadCommunityNames,
snmpInBadCommunityUses,
snmpInASNParseErrs,
snmpInTooBigs,
snmpInNoSuchNames,
snmpInBadValues,
snmpInReadOnlys,
snmpInGenErrs,
snmpInTotalReqVars,
snmpInTotalSetVars,
snmpInGetRequests,
snmpInSetRequests,
snmpInGetNexts,
snmpInGetResponses,
snmpInTraps,
snmpOutTooBigs,
snmpOutNoSuchNames,
snmpOutBadValues,
snmpOutGenErrs,
snmpOutGetRequests,
snmpOutSetRequests,
snmpOutGetNexts,
snmpOutGetResponses,
snmpOutTraps
]
},
{snmp_framework_mib,
[
],
[
snmpEngineID,
snmpEngineBoots,
snmpEngineTime,
snmpEngineMaxMessageSize
]
},
{snmp_view_based_acm_mib,
[
vacmAccessTable,
vacmSecurityToGroupTable,
vacmViewTreeFamilyTable
],
[
vacmViewSpinLock
]
},
{snmp_target_mib,
[
snmpTargetAddrTable,
snmpTargetParamsTable
],
[
snmpTargetSpinLock
]
},
{snmp_community_mib,
[
snmpCommunityTable
],
[]
},
{snmp_notification_mib,
[
snmpNotifyTable
],
[]},
{snmp_user_based_sm_mib,
[
usmUserTable
],