SlideShare ist ein Scribd-Unternehmen logo
1 von 17
NET-SNMP API for v1/v2c
AGENDA
• SNMP v1 protocol
• SNMP v2c protocol
• Net-SNMP Apps
– snmpget, snmpgetnext, snmpset, snmpbulkget
– snmptrap
– snmptrapd
– Others Apps
SNMP v1 protocol
• SNMP GET : 取得某些OID的值
• SNMP SET : 設定某些OID的值
• SNMP GET-NEXT : 取得某些OID的下一個OID
與值
• SNMP Walk : 透過Get Next去取得整個tree的
資料,只能walk一個OID
• SNMP trap : 發生特定事件時,設備主動送
出的封包
SNMP v2c protocol
• SNMP Bulk Get : 用來減少Get-NEXT封包
– Non-Repeaters : 哪幾個OID不做GETNEXT查詢
– Max-Repetitions : 在同一個封包內最多裝幾個
response
• snmpbulkget -v2c -Cn1 -Cr5 -Os -c public 172.18.3.43
system ifTable
sysDescr.0 = STRING: "SunOS zeus.net.cmu.edu 4.1.3_U1 1 sun4m"
ifIndex.1 = INTEGER: 1
ifIndex.2 = INTEGER: 2
ifDescr.1 = STRING: "lo0“
…..
SNMP v2c protocol
• SNMP Bulk Walk : 用Bulk get去取得整個tree的
資料 (只能walk一個OID下)
– Cc : 不檢查回傳的OID是否有照順序
– Cp : 印出所查詢的數量
– Ci : 所回傳的資料要包含輸入的OID
– Cn : 設定Non-Repeaters
– Cr : 設定Max-Repetitions
• snmpbulkwalk –v2c –c public 172.18.3.43 system
sysDescr.0 = STRING: "SunOS zeus.net.cmu.edu 4.1.3_U1 1 sun4m"
sysObjectID.0 = OID: enterprises.hp.nm.hpsystem.10.1.1
sysUpTime.0 = Timeticks: (155274552) 17 days, 23:19:05
…
SNMP v2c protocol
• SNMP inform : 跟trap雷同,但是送出封包後
要等接收端來的回應,要不然會一直送。
NET-SNMP API - snmpget
1. netsnmp_parse_args()
2. ss = snmp_open(&session)
3. snmp_pdu_create(SNMP_MSG_GET)
4. snmp_add_null_var(pdu, oid, oid_length)
5. snmp_synch_response(ss, pdu, &reponse)
6. snmp_free_pdu(response)
7. snmp_close(ss)
NET-SNMP API - snmpgetnext
1. netsnmp_parse_args()
2. ss = snmp_open(&session)
3. snmp_pdu_create(SNMP_MSG_GETNEXT)
4. snmp_add_null_var(pdu, oid, oid_length)
5. snmp_synch_response(ss, pdu, &reponse)
6. snmp_free_pdu(response)
7. snmp_close(ss)
NET-SNMP API - snmpset
1. netsnmp_parse_args()
2. ss = snmp_open(&session)
3. snmp_pdu_create(SNMP_MSG_SET)
4. snmp_add_var(pdu, oid, oid_length,
valute_type, value)
5. snmp_synch_response(ss, pdu, & reponse)
6. snmp_free_pdu(response)
7. snmp_close(ss)
NET-SNMP API - snmpbulkget
1. netsnmp_parse_args()
2. ss = snmp_open(&session)
3. snmp_pdu_create(SNMP_MSG_GETBULK)
– pdu->non_repeaters = non_repeaters;
– pdu->max_repetitions = max_repetitions;
4. snmp_add_null_var(pdu, oid, oid_length)
5. snmp_synch_response(ss, pdu, &reponse)
6. snmp_free_pdu(response)
7. snmp_close(ss)
NET-SNMP API - snmptrap –v1
1. snmp_parse_args()
2. ss = snmp_add(&session,
netsnmp_transport_open_client("snmptrap", session.peername), NULL,
NULL);
3. snmp_pdu_create(SNMP_MSG_TRAP)
– memcpy(pdu->enterprise, name, name_length * sizeof(oid));
– pdu->enterprise_length = name_length;
– pdu->trap_type = atoi(trap);
– pdu->specific_type = atoi(specific);
– pdu->time = atol(description);
4. snmp_add_var (pdu, binding_name, binding_name_length, value_type,
value); …
5. status = snmp_send(ss, pdu)
6. snmp_free_pdu(pdu)
7. snmp_close(ss)
NET-SNMP API - snmptrap –v2
1. snmp_parse_args()
2. ss =
snmp_add(&session, netsnmp_transport_open_client("s
nmptrap", session.peername), NULL, NULL);
3. snmp_pdu_create(SNMP_MSG_TRAP2)
4. snmp_add_var(pdu, objid_sysuptime, sizeof(objid_sysu
ptime) / sizeof(oid), 't', trap);
5. snmp_add_var(pdu, oid, oid_length, valute_type, value)
6. snmp_add_var
(pdu, binding_name, binding_name_length, value_type, value); …
7. status = snmp_send(ss, pdu)
8. snmp_free_pdu(pdu)
9. snmp_close(ss)
NET-SNMP API - snmptrap –Ci (inform)
1. snmp_parse_args()
2. ss =
snmp_add(&session, netsnmp_transport_open_client("s
nmptrap", session.peername), NULL, NULL);
3. snmp_pdu_create(SNMP_MSG_INFORM)
4. snmp_add_var(pdu, objid_sysuptime, sizeof(objid_sysu
ptime) / sizeof(oid), 't', trap);
5. snmp_add_var(pdu, oid, oid_length, valute_type, value)
6. snmp_add_var
(pdu, binding_name, binding_name_length, value_type, value); …
7. status = snmp_synch_response(ss, pdu, &response);
8. snmp_free_pdu(response)
9. snmp_close(ss)
NET-SNMP API - snmptrapd
• SnmpTrapdMain
1. SIGTERM / SIGINT / SIGHUP / SIGPIPE
2. snmptrapd_register_configs
1. register_config_handler
3. //Process the options & // Process AGENTX
4. init_snmp
5. netsnmp_transport_open_server
6. snmptrapd_add_session
• snmp_input
7. snmptrapd_main_loop
8. snmptrapd_close_sessions
9. snmp_shutdown
NET-SNMP API - snmptrapd handler
• syslog_handler (存到syslog)
• print_handler (存到檔案)
• command_handler (執行對應的script)
• axforward_handler (將這個trap)
• forward_handler (將這個trap轉送到其他的
receiver)
NET-SNMP API - snmp_input
1. 先將收到的trap OID取出
– 將SNMP v1 trap轉為v2的格式
2. netsnmp_auth_global_traphandlers
3. netsnmp_pre_global_traphandlers
– syslog_handler
– print_handler
4. netsnmp_specific_traphandlers |
netsnmp_default_traphandlers
– command_handler
– forward_handler 或 axforward_handler
5. netsnmp_post_global_traphandlers
NET-SNMP other apps
• snmpusm : SNMPv3 安全認證
• snmpvacm : SNMPv3 存取控制
• snmpdf : 看系統的硬碟與記憶體使用狀況
• snmptable : 輸入某個table的OID,會用table方式呈現
• snmpd : SNMP agent daemon
• snmpdelta : 持續監控某些OID,若有不同才會show
• snmpnetstat : 類似netstat,看目前開啟了哪些port
• snmpstatus : 取得網路使用量的資訊
• snmptest : 用來測試Get/Set/GetNext/GetBulk/Trap等功能
的狀況
• snmptranslate : OID與Name之間的轉換

Weitere ähnliche Inhalte

Empfohlen

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Empfohlen (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Net snmp API

  • 2. AGENDA • SNMP v1 protocol • SNMP v2c protocol • Net-SNMP Apps – snmpget, snmpgetnext, snmpset, snmpbulkget – snmptrap – snmptrapd – Others Apps
  • 3. SNMP v1 protocol • SNMP GET : 取得某些OID的值 • SNMP SET : 設定某些OID的值 • SNMP GET-NEXT : 取得某些OID的下一個OID 與值 • SNMP Walk : 透過Get Next去取得整個tree的 資料,只能walk一個OID • SNMP trap : 發生特定事件時,設備主動送 出的封包
  • 4. SNMP v2c protocol • SNMP Bulk Get : 用來減少Get-NEXT封包 – Non-Repeaters : 哪幾個OID不做GETNEXT查詢 – Max-Repetitions : 在同一個封包內最多裝幾個 response • snmpbulkget -v2c -Cn1 -Cr5 -Os -c public 172.18.3.43 system ifTable sysDescr.0 = STRING: "SunOS zeus.net.cmu.edu 4.1.3_U1 1 sun4m" ifIndex.1 = INTEGER: 1 ifIndex.2 = INTEGER: 2 ifDescr.1 = STRING: "lo0“ …..
  • 5. SNMP v2c protocol • SNMP Bulk Walk : 用Bulk get去取得整個tree的 資料 (只能walk一個OID下) – Cc : 不檢查回傳的OID是否有照順序 – Cp : 印出所查詢的數量 – Ci : 所回傳的資料要包含輸入的OID – Cn : 設定Non-Repeaters – Cr : 設定Max-Repetitions • snmpbulkwalk –v2c –c public 172.18.3.43 system sysDescr.0 = STRING: "SunOS zeus.net.cmu.edu 4.1.3_U1 1 sun4m" sysObjectID.0 = OID: enterprises.hp.nm.hpsystem.10.1.1 sysUpTime.0 = Timeticks: (155274552) 17 days, 23:19:05 …
  • 6. SNMP v2c protocol • SNMP inform : 跟trap雷同,但是送出封包後 要等接收端來的回應,要不然會一直送。
  • 7. NET-SNMP API - snmpget 1. netsnmp_parse_args() 2. ss = snmp_open(&session) 3. snmp_pdu_create(SNMP_MSG_GET) 4. snmp_add_null_var(pdu, oid, oid_length) 5. snmp_synch_response(ss, pdu, &reponse) 6. snmp_free_pdu(response) 7. snmp_close(ss)
  • 8. NET-SNMP API - snmpgetnext 1. netsnmp_parse_args() 2. ss = snmp_open(&session) 3. snmp_pdu_create(SNMP_MSG_GETNEXT) 4. snmp_add_null_var(pdu, oid, oid_length) 5. snmp_synch_response(ss, pdu, &reponse) 6. snmp_free_pdu(response) 7. snmp_close(ss)
  • 9. NET-SNMP API - snmpset 1. netsnmp_parse_args() 2. ss = snmp_open(&session) 3. snmp_pdu_create(SNMP_MSG_SET) 4. snmp_add_var(pdu, oid, oid_length, valute_type, value) 5. snmp_synch_response(ss, pdu, & reponse) 6. snmp_free_pdu(response) 7. snmp_close(ss)
  • 10. NET-SNMP API - snmpbulkget 1. netsnmp_parse_args() 2. ss = snmp_open(&session) 3. snmp_pdu_create(SNMP_MSG_GETBULK) – pdu->non_repeaters = non_repeaters; – pdu->max_repetitions = max_repetitions; 4. snmp_add_null_var(pdu, oid, oid_length) 5. snmp_synch_response(ss, pdu, &reponse) 6. snmp_free_pdu(response) 7. snmp_close(ss)
  • 11. NET-SNMP API - snmptrap –v1 1. snmp_parse_args() 2. ss = snmp_add(&session, netsnmp_transport_open_client("snmptrap", session.peername), NULL, NULL); 3. snmp_pdu_create(SNMP_MSG_TRAP) – memcpy(pdu->enterprise, name, name_length * sizeof(oid)); – pdu->enterprise_length = name_length; – pdu->trap_type = atoi(trap); – pdu->specific_type = atoi(specific); – pdu->time = atol(description); 4. snmp_add_var (pdu, binding_name, binding_name_length, value_type, value); … 5. status = snmp_send(ss, pdu) 6. snmp_free_pdu(pdu) 7. snmp_close(ss)
  • 12. NET-SNMP API - snmptrap –v2 1. snmp_parse_args() 2. ss = snmp_add(&session, netsnmp_transport_open_client("s nmptrap", session.peername), NULL, NULL); 3. snmp_pdu_create(SNMP_MSG_TRAP2) 4. snmp_add_var(pdu, objid_sysuptime, sizeof(objid_sysu ptime) / sizeof(oid), 't', trap); 5. snmp_add_var(pdu, oid, oid_length, valute_type, value) 6. snmp_add_var (pdu, binding_name, binding_name_length, value_type, value); … 7. status = snmp_send(ss, pdu) 8. snmp_free_pdu(pdu) 9. snmp_close(ss)
  • 13. NET-SNMP API - snmptrap –Ci (inform) 1. snmp_parse_args() 2. ss = snmp_add(&session, netsnmp_transport_open_client("s nmptrap", session.peername), NULL, NULL); 3. snmp_pdu_create(SNMP_MSG_INFORM) 4. snmp_add_var(pdu, objid_sysuptime, sizeof(objid_sysu ptime) / sizeof(oid), 't', trap); 5. snmp_add_var(pdu, oid, oid_length, valute_type, value) 6. snmp_add_var (pdu, binding_name, binding_name_length, value_type, value); … 7. status = snmp_synch_response(ss, pdu, &response); 8. snmp_free_pdu(response) 9. snmp_close(ss)
  • 14. NET-SNMP API - snmptrapd • SnmpTrapdMain 1. SIGTERM / SIGINT / SIGHUP / SIGPIPE 2. snmptrapd_register_configs 1. register_config_handler 3. //Process the options & // Process AGENTX 4. init_snmp 5. netsnmp_transport_open_server 6. snmptrapd_add_session • snmp_input 7. snmptrapd_main_loop 8. snmptrapd_close_sessions 9. snmp_shutdown
  • 15. NET-SNMP API - snmptrapd handler • syslog_handler (存到syslog) • print_handler (存到檔案) • command_handler (執行對應的script) • axforward_handler (將這個trap) • forward_handler (將這個trap轉送到其他的 receiver)
  • 16. NET-SNMP API - snmp_input 1. 先將收到的trap OID取出 – 將SNMP v1 trap轉為v2的格式 2. netsnmp_auth_global_traphandlers 3. netsnmp_pre_global_traphandlers – syslog_handler – print_handler 4. netsnmp_specific_traphandlers | netsnmp_default_traphandlers – command_handler – forward_handler 或 axforward_handler 5. netsnmp_post_global_traphandlers
  • 17. NET-SNMP other apps • snmpusm : SNMPv3 安全認證 • snmpvacm : SNMPv3 存取控制 • snmpdf : 看系統的硬碟與記憶體使用狀況 • snmptable : 輸入某個table的OID,會用table方式呈現 • snmpd : SNMP agent daemon • snmpdelta : 持續監控某些OID,若有不同才會show • snmpnetstat : 類似netstat,看目前開啟了哪些port • snmpstatus : 取得網路使用量的資訊 • snmptest : 用來測試Get/Set/GetNext/GetBulk/Trap等功能 的狀況 • snmptranslate : OID與Name之間的轉換