merge
This commit is contained in:
commit
0b094b8df2
@ -1,5 +1,8 @@
|
||||
<Properties StartupItem="Snmp2Mysql/Snmp2Mysql.csproj">
|
||||
<MonoDevelop.Ide.Workspace ActiveConfiguration="Release" />
|
||||
<<<<<<< local
|
||||
<MonoDevelop.Ide.Workbench />
|
||||
=======
|
||||
<MonoDevelop.Ide.Workbench ActiveDocument="Snmp2Mysql/Program.cs">
|
||||
<Files>
|
||||
<File FileName="Snmp2Mysql/DatabaseLink.cs" Line="1" Column="1" />
|
||||
@ -7,6 +10,7 @@
|
||||
<File FileName="Snmp2Mysql/SnmpGetter.cs" Line="1" Column="1" />
|
||||
</Files>
|
||||
</MonoDevelop.Ide.Workbench>
|
||||
>>>>>>> other
|
||||
<MonoDevelop.Ide.DebuggingService.Breakpoints>
|
||||
<BreakpointStore />
|
||||
</MonoDevelop.Ide.DebuggingService.Breakpoints>
|
||||
|
@ -3,4 +3,8 @@
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
|
||||
</startup>
|
||||
</configuration>
|
||||
<appSettings>
|
||||
<add key="DbConnStr" value="SERVER=localhost; DATABASE=statsdb; UID=statsuser; PASSWORD=test123;"/>
|
||||
<add key="Verbose" value="true"/>
|
||||
</appSettings>
|
||||
</configuration>
|
||||
|
@ -1,55 +1,72 @@
|
||||
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) {
|
||||
// Console.WriteLine ("{0}, no result: {1}", dt.Description, e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Configuration;
|
||||
|
||||
namespace Snmp2Mysql
|
||||
{
|
||||
class Snmp2MysqlException : Exception
|
||||
{
|
||||
public Snmp2MysqlException(string msg) : base(msg) {}
|
||||
public Snmp2MysqlException(string msg, Exception rootCause) : base(msg, rootCause) { }
|
||||
}
|
||||
|
||||
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
//string loc = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
|
||||
//Console.WriteLine ("loc: {0}", loc);
|
||||
|
||||
string dbConnStr = ConfigurationManager.AppSettings["DbConnStr"];
|
||||
if (dbConnStr == null || "".Equals (dbConnStr)) {
|
||||
throw new Snmp2MysqlException ("dbConnStr not found in configuration");
|
||||
}
|
||||
string verboseStr = ConfigurationManager.AppSettings ["Verbose"];
|
||||
if (verboseStr == null || "".Equals (verboseStr)) {
|
||||
throw new Snmp2MysqlException ("Verbose not found in configuration");
|
||||
}
|
||||
bool verbose = verboseStr.ToUpper().Equals ("TRUE");
|
||||
|
||||
if (verbose)
|
||||
Console.WriteLine ("Database connection to {0}", dbConnStr);
|
||||
DatabaseLink dbLink = new DatabaseLink(dbConnStr);
|
||||
using (DataCollector dc = dbLink.DataCollector)
|
||||
using (DeviceProvider dp = dbLink.DeviceProvider)
|
||||
{
|
||||
foreach (DeviceTuple dt in dp)
|
||||
{
|
||||
if (verbose) 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)
|
||||
{
|
||||
if (verbose) 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)
|
||||
{
|
||||
if (verbose) Console.WriteLine("{0} {1} {2}: {3}", r.Index, r.Oid, r.Type, r.Value);
|
||||
dc.add((int)r.Index, r.Value);
|
||||
}
|
||||
}
|
||||
catch (SnmpGetterException e) {
|
||||
if (verbose) Console.WriteLine ("no result: {0}", e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -45,6 +45,7 @@
|
||||
<Reference Include="SnmpSharpNet">
|
||||
<HintPath>dependencies\SnmpSharpNet.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Configuration" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="DatabaseLink.cs" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user