コード例 #1
0
func coreSwIfMap(ip string, limitch chan bool) {
	pingResult := pingCheck(ip)
	snmpWalk := false

	if !pingResult {
		DeletePortMap(ip)
		<-limitch
		return
	}
	vendor, err := sw.SysVendor(ip, community, snmpTimeout)
	if err != nil {
		return
	}
	if !slice.ContainsString(AliveIp, ip) {
		AliveIp = append(AliveIp, ip)
	}
	snmpWalk = true
	log.Println("port map add ", ip, vendor)
	if !snmpWalk {
		MapIfName(ip)
	} else {
		MapIfNameWalk(ip)
	}

}
コード例 #2
0
func coreSwIfMetrics(ip string, ch chan ChIfStat, limitCh chan bool) {
	var startTime, endTime int64
	startTime = time.Now().Unix()

	var chIfStat ChIfStat

	pingResult := pingCheck(ip)

	chIfStat.Ip = ip
	chIfStat.PingResult = pingResult

	if !pingResult {
		endTime = time.Now().Unix()
		chIfStat.UseTime = (endTime - startTime)
		<-limitCh
		ch <- chIfStat
		return
	} else {
		var ifList []sw.IfStats
		var err error

		vendor, _ := sw.SysVendor(ip, community, snmpTimeout)
		if vendor == "Huawei" || vendor == "Cisco_IOS_XR" {
			ifList, err = sw.ListIfStatsSnmpWalk(ip, community, snmpTimeout*5, ignoreIface, snmpRetry, ignorePkt, ignoreOperStatus, ignoreBroadcastPkt, ignoreMulticastPkt)
		} else {
			ifList, err = sw.ListIfStats(ip, community, snmpTimeout, ignoreIface, snmpRetry, ignorePkt, ignoreOperStatus, ignoreBroadcastPkt, ignoreMulticastPkt)
		}

		if err != nil {
			log.Printf(ip, err)
		}

		if len(ifList) > 0 {
			chIfStat.IfStatsList = &ifList
		}

		endTime = time.Now().Unix()
		chIfStat.UseTime = (endTime - startTime)
		<-limitCh
		ch <- chIfStat
		return
	}

	return
}
コード例 #3
0
ファイル: swconn.go プロジェクト: freedomkk-qfeng/swcollector
func connMetrics(ip string, ch chan SwConn) {
	var swConn SwConn
	vendor, _ := sw.SysVendor(ip, community, snmpTimeout)
	if !strings.Contains(vendor, "Cisco_ASA") {
		ch <- swConn
		return
	}
	ConnectionStat, err := sw.ConnectionStat(ip, g.Config().Switch.Community, g.Config().Switch.SnmpTimeout, g.Config().Switch.SnmpRetry)
	if err != nil {
		log.Println(err)
	}

	swConn.Ip = ip
	swConn.ConnectionStat = ConnectionStat
	ch <- swConn

	return
}