print device description
This commit is contained in:
parent
4df6273c95
commit
9285eaaaee
@ -67,11 +67,13 @@ namespace Snmp2Mysql
|
||||
{
|
||||
private int mId;
|
||||
private string mOid;
|
||||
private string mDescription;
|
||||
|
||||
public DeviceDataItemTuple(int id, string oid)
|
||||
public DeviceDataItemTuple(int id, string oid, string description)
|
||||
{
|
||||
mId = id;
|
||||
mOid = oid;
|
||||
mDescription = description;
|
||||
}
|
||||
|
||||
public int Id
|
||||
@ -83,6 +85,10 @@ namespace Snmp2Mysql
|
||||
{
|
||||
get { return mOid; }
|
||||
}
|
||||
|
||||
public string Description {
|
||||
get { return mDescription; }
|
||||
}
|
||||
}
|
||||
|
||||
class DeviceDataItemProvider : DatabaseConnectionHelper, IEnumerable<DeviceDataItemTuple>
|
||||
@ -101,7 +107,7 @@ namespace Snmp2Mysql
|
||||
|
||||
IEnumerator<DeviceDataItemTuple> IEnumerable<DeviceDataItemTuple>.GetEnumerator()
|
||||
{
|
||||
string stmt = "SELECT dedi.id, di.oid FROM devicedataitem_t dedi, dataitem_t di WHERE dedi.device = " + mDevice + " AND dedi.dataitem = di.id";
|
||||
string stmt = "SELECT dedi.id, di.oid, di.description FROM devicedataitem_t dedi, dataitem_t di WHERE dedi.device = " + mDevice + " AND dedi.dataitem = di.id";
|
||||
MySqlCommand cmd = new MySqlCommand(stmt, mConn);
|
||||
|
||||
using (MySqlDataReader reader = cmd.ExecuteReader())
|
||||
@ -109,7 +115,7 @@ namespace Snmp2Mysql
|
||||
while (reader.Read())
|
||||
{
|
||||
// Console.WriteLine("{0} {1}", reader[0], reader[1]);
|
||||
DeviceDataItemTuple r = new DeviceDataItemTuple((int)reader[0], (string)reader[1]);
|
||||
DeviceDataItemTuple r = new DeviceDataItemTuple((int)reader[0], (string)reader[1], (string)reader[2]);
|
||||
yield return r;
|
||||
}
|
||||
}
|
||||
@ -123,12 +129,14 @@ namespace Snmp2Mysql
|
||||
private DeviceDataItemProvider mDeviceDataItemProvider;
|
||||
private string mDeviceAddress;
|
||||
private string mCommunity;
|
||||
private string mDescription;
|
||||
|
||||
public DeviceTuple(DeviceDataItemProvider deviceDataItemProvider, string deviceAddress, string community)
|
||||
public DeviceTuple(DeviceDataItemProvider deviceDataItemProvider, string deviceAddress, string community, string description)
|
||||
{
|
||||
mDeviceDataItemProvider = deviceDataItemProvider;
|
||||
mDeviceAddress = deviceAddress;
|
||||
mCommunity = community;
|
||||
mDescription = description;
|
||||
}
|
||||
|
||||
public DeviceDataItemProvider DeviceDataItemProvider
|
||||
@ -145,6 +153,10 @@ namespace Snmp2Mysql
|
||||
{
|
||||
get { return mCommunity; }
|
||||
}
|
||||
|
||||
public string Description {
|
||||
get { return mDescription; }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -160,7 +172,7 @@ namespace Snmp2Mysql
|
||||
|
||||
IEnumerator<DeviceTuple> IEnumerable<DeviceTuple>.GetEnumerator()
|
||||
{
|
||||
string stmt = "SELECT id, address, community FROM device_t";
|
||||
string stmt = "SELECT id, address, community, description FROM device_t";
|
||||
MySqlCommand cmd = new MySqlCommand(stmt, mConn);
|
||||
|
||||
using (MySqlDataReader reader = cmd.ExecuteReader())
|
||||
@ -171,8 +183,9 @@ namespace Snmp2Mysql
|
||||
int deviceId = (int)reader[0];
|
||||
string deviceAddress = (string)reader[1];
|
||||
string community = (string)reader[2];
|
||||
string description = (string)reader[3];
|
||||
DeviceDataItemProvider deviceDataItemProvider = new DeviceDataItemProvider(mDbConnStr, deviceId);
|
||||
DeviceTuple r = new DeviceTuple(deviceDataItemProvider, deviceAddress, community);
|
||||
DeviceTuple r = new DeviceTuple(deviceDataItemProvider, deviceAddress, community, description);
|
||||
yield return r;
|
||||
}
|
||||
}
|
||||
|
@ -1,55 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Snmp2Mysql
|
||||
{
|
||||
|
||||
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
string dbConnStr = "SERVER=localhost;" +
|
||||
"DATABASE=statsdb;" +
|
||||
"UID=statsuser;" +
|
||||
"PASSWORD=test123;";
|
||||
DatabaseLink dbLink = new DatabaseLink(dbConnStr);
|
||||
using (DataCollector dc = dbLink.DataCollector)
|
||||
using (DeviceProvider dp = dbLink.DeviceProvider)
|
||||
{
|
||||
foreach (DeviceTuple dt in dp)
|
||||
{
|
||||
// Console.WriteLine("dt: {0}, {1}", dt.DeviceAddress, dt.Community);
|
||||
|
||||
using (SnmpGetter snmpGetter = new SnmpGetter(dt.Community, dt.DeviceAddress))
|
||||
{
|
||||
using (DeviceDataItemProvider ddip = dt.DeviceDataItemProvider)
|
||||
{
|
||||
foreach (DeviceDataItemTuple ddit in dt.DeviceDataItemProvider)
|
||||
{
|
||||
// Console.WriteLine(" ddit: {0}, {1}", ddit.Id, ddit.Oid);
|
||||
snmpGetter.AddOid(ddit.Id, ddit.Oid);
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
SnmpGetterResultProvider res = snmpGetter.Exec();
|
||||
foreach (SnmpGetterResult r in res)
|
||||
{
|
||||
Console.WriteLine("{0} {1} {2}: {3}", r.Index, r.Oid, r.Type, r.Value);
|
||||
dc.add((int)r.Index, r.Value);
|
||||
}
|
||||
}
|
||||
catch (SnmpGetterException e) {
|
||||
Console.WriteLine ("no result: {0}", e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Snmp2Mysql
|
||||
{
|
||||
|
||||
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
string dbConnStr = "SERVER=localhost;" +
|
||||
"DATABASE=statsdb;" +
|
||||
"UID=statsuser;" +
|
||||
"PASSWORD=test123;";
|
||||
DatabaseLink dbLink = new DatabaseLink(dbConnStr);
|
||||
using (DataCollector dc = dbLink.DataCollector)
|
||||
using (DeviceProvider dp = dbLink.DeviceProvider)
|
||||
{
|
||||
foreach (DeviceTuple dt in dp)
|
||||
{
|
||||
// Console.WriteLine("dt: {0}, {1}", dt.DeviceAddress, dt.Community);
|
||||
|
||||
using (SnmpGetter snmpGetter = new SnmpGetter(dt.Community, dt.DeviceAddress))
|
||||
{
|
||||
using (DeviceDataItemProvider ddip = dt.DeviceDataItemProvider)
|
||||
{
|
||||
foreach (DeviceDataItemTuple ddit in dt.DeviceDataItemProvider)
|
||||
{
|
||||
// Console.WriteLine(" ddit: {0}, {1}", ddit.Id, ddit.Oid);
|
||||
snmpGetter.AddOid(ddit.Id, ddit.Oid);
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
SnmpGetterResultProvider res = snmpGetter.Exec();
|
||||
foreach (SnmpGetterResult r in res)
|
||||
{
|
||||
Console.WriteLine("{0} {1} {2} {3}: {4}", dt.Description, r.Index, r.Oid, r.Type, r.Value);
|
||||
dc.add((int)r.Index, r.Value);
|
||||
}
|
||||
}
|
||||
catch (SnmpGetterException e) {
|
||||
Console.WriteLine ("{0}, no result: {1}", dt.Description, e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user