No5. net-snmp 《精通SNMP》读书笔记--第四章 管理信息结构

本文深入探讨了SNMP管理信息结构(SMI)的核心概念,包括被管理对象、对象类型及MIB的定义。详细解释了如何使用宏OBJECT-TYPE在MIB中定义对象,以及对象标识符和对象描述符在ASN.1中的应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

《精通SNMP》读书笔记    ------------------------------------------------------      

                                                        第四章  管理信息结构

 

管理信息结构SMI的主要内容有三部分:

1. 是为MIB中定义的被管理对象分配对象标识符(OID)空间。

2. 是定义了宏OBJECT-TYPE,用来在MIB中定义被管理对象。

3. 是定义了被管理对象可以使用的ASN.1集合。

 

这一章主要讲的就是第二条,如何使用宏OBJECT-TYPE在MIB中定义被管理对象。

 

【被管理对象】完整描述一种特定管理信息的所有要素的集合,就是一个特定的被管理对象(managed object)

 

【对象类型】一个被管理对象对应一种或一类管理信息,表示管理信息的ASN。1类型、标识和传输编码加在一起,称为对象类型(object type)

 

【MIB】一组相关的被管理对象和一些辅助的类型、值定义,被组织在一个ASN.1模块中,那么该模块就是一个MIB

 

4.1.2 对象标识与语法

 

被管理对象使用对象标识符作为标识。

 

【对象描述符】每种被管理对象都有一个文本名(又称对象描述符),和对象标识符一样可以唯一标识一种对象类型。从ASN.1语法的角度看,对象描述符是一个OBJECT IDENTIFIER类型的值名字,和赋给它的值(对象标识符)是等价的。

 

directory             OBJECT INENTIFIER::={internet  1}

 

directory   就是对象描述符,这是字符串。

.1.3.6.1.1   就是对象标识符,这是一串数字。

--------------------------------------------------------------------------------------------------

用C语言举个例子。int  aboy = 3;    aboy 和 3就是等价的。

aboy 就相当于   对象描述符。

3    就相当于   对象标识符。

---------------------------------------------------------------------------------------------------

这两个概念,必须搞清楚,文中的讲解,围绕这两个词绕来绕去。

<template> <div class="operation-container"> <!-- 顶部信息卡片 --> <el-card class="header-card"> <div class="header-content"> <div class="info-item"> <div class="label">问卷标题:</div> <div class="value">{{ detailData.dcWjTitle || '--' }}</div> </div> <div class="info-item"> <div class="label">被测评人:</div> <div class="value">{{ detailData.dcName || '--' }}</div> </div> <div class="info-item"> <div class="label">部门:</div> <div class="value">{{ detailData.dcDept || '--' }}</div> </div> </div> </el-card> <!-- 问卷问题区域 --> <el-card class="question-card" v-for="(question, index) in questions" :key="index"> <div class="question-header"> <div class="question-title">{{ question.id }}、{{ question.content }}</div> <el-tag type="success">已选择: {{ getOptionText(question, detailData[question.field]) }}</el-tag> </div> <div class="options-container"> <div v-for="(option, optIndex) in question.options" :key="optIndex" class="option-item" :class="{ 'selected': detailData[question.field] == option.value, 'disabled': detailData.state === '1' }" > <div class="option-label">{{ option.label }}</div> <div class="option-value">({{ option.value }})</div> </div> </div> </el-card> <!-- 底部操作按钮 --> <div class="action-buttons"> <el-button type="primary" size="large" @click="handleSubmit" :disabled="detailData.state === '1'" > {{ detailData.state === '1' ? '已提交' : '提交问卷' }} </el-button> <el-button size="large" @click="handleBack" > 返回列表 </el-button> </div> </div> </template> <script setup> import { ref, reactive, onMounted } from 'vue'; import { useRoute, useRouter } from 'vue-router'; import axios from 'axios'; import { ElMessage } from 'element-plus'; const route = useRoute(); const router = useRouter(); // 环境变量管理API地址 const API_BASE = import.meta.env.VITE_API_BASE || 'http://172.26.26.43/dev-api'; // 问卷详情数据 const detailData = reactive({}); const loading = ref(false); const wjId = ref(null); // 问题配置 const questions = reactive([ { id: 1, field: 'no1', content: '被测评人员是否具有较高的"核心与看齐意识"能够坚持贯彻执行公司的决策部署', options: [ { label: '很不赞同', value: 1 }, { label: '不赞同', value: 2 }, { label: '一般', value: 3 }, { label: '赞同', value: 4 }, { label: '很赞同', value: 5 } ] }, // 其他问题配置(实际使用时需要补充完整) { id: 2, field: 'no2', content: '问题二内容...', options: [ // 选项配置... ] }, // 更多问题... ]); // 获取选项文本 const getOptionText = (question, value) => { const option = question.options.find(opt => opt.value == value); return option ? option.label : '未选择'; }; // 获取问卷ID onMounted(() => { wjId.value = route.params.id; if (wjId.value) { fetchDetail(); } else { ElMessage.error('未获取到问卷ID'); router.back(); } }); // 获取认证令牌 const getAuthToken = () => { const token = localStorage.getItem('token'); if (!token) { ElMessage.warning('请先登录'); router.push('/login'); return null; } return token; }; // 获取问卷详情 const fetchDetail = async () => { const token = getAuthToken(); if (!token) return; loading.value = true; try { const response = await axios.get(`${API_BASE}/wjdc/wj/${wjId.value}`, { headers: { 'Authorization': `Bearer ${token}` } }); if (response.data && response.data.code === 200) { Object.assign(detailData, response.data.data || {}); ElMessage.success('问卷数据加载成功'); } else { const errorMsg = response.data?.msg || '获取问卷详情失败'; ElMessage.error(errorMsg); } } catch (error) { console.error('获取问卷详情失败:', error); let errorMsg = '网络请求失败'; if (error.response) { if (error.response.status === 401) { errorMsg = '认证过期,请重新登录'; localStorage.removeItem('token'); router.push('/login'); } else if (error.response.data?.msg) { errorMsg = error.response.data.msg; } } ElMessage.error(`获取问卷详情失败: ${errorMsg}`); } finally { loading.value = false; } }; // 提交问卷 const handleSubmit = () => { ElMessage.success('问卷提交成功'); detailData.state = '1'; }; // 返回列表 const handleBack = () => { router.push({ name: 'Detail' }); }; </script> <style scoped> .operation-container { padding: 16px; max-width: 1200px; margin: 0 auto; } /* 顶部信息卡片 */ .header-card { border-radius: 12px; margin-bottom: 20px; box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08); } .header-content { display: flex; flex-wrap: wrap; gap: 20px 40px; } .info-item { display: flex; align-items: center; min-width: 300px; } .label { font-weight: 600; color: #606266; font-size: 16px; min-width: 80px; } .value { font-size: 18px; color: #303133; font-weight: 500; } /* 问题卡片 */ .question-card { border-radius: 12px; margin-bottom: 20px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06); } .question-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; padding-bottom: 15px; border-bottom: 1px solid #eee; } .question-title { font-size: 18px; font-weight: 600; color: #1a1a1a; flex: 1; margin-right: 20px; } /* 选项容器 */ .options-container { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 15px; } .option-item { display: flex; align-items: center; padding: 12px 15px; border: 1px solid #dcdfe6; border-radius: 6px; transition: all 0.3s; cursor: pointer; } .option-item:hover:not(.disabled) { background-color: #f5f7fa; border-color: #c0c4cc; } .option-item.selected { background-color: #ecf5ff; border-color: #409eff; color: #409eff; } .option-item.disabled { cursor: not-allowed; opacity: 0.7; } .option-label { flex: 1; font-size: 16px; } .option-value { font-weight: 600; margin-left: 10px; min-width: 40px; text-align: center; } /* 操作按钮 */ .action-buttons { display: flex; justify-content: center; gap: 30px; margin-top: 30px; } /* 响应式设计 */ @media (max-width: 768px) { .header-content { flex-direction: column; gap: 15px; } .info-item { min-width: auto; width: 100%; } .question-header { flex-direction: column; align-items: flex-start; gap: 10px; } .options-container { grid-template-columns: 1fr; } .action-buttons { flex-direction: column; gap: 15px; } .action-buttons .el-button { width: 100%; } } @media (max-width: 480px) { .question-title { font-size: 16px; } .option-item { padding: 10px; } .option-label { font-size: 14px; } } </style> 帮我优化一下,每个问题的选项是一样的只是问题不同
最新发布
07-17
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Ricardo于

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值