diff --git a/Snmp2Mysql.userprefs b/Snmp2Mysql.userprefs index 54d3486..d435b3c 100644 --- a/Snmp2Mysql.userprefs +++ b/Snmp2Mysql.userprefs @@ -1,11 +1,15 @@  +<<<<<<< local + +======= +>>>>>>> other diff --git a/Snmp2Mysql/App.config b/Snmp2Mysql/App.config index fad249e..3cdd758 100644 --- a/Snmp2Mysql/App.config +++ b/Snmp2Mysql/App.config @@ -3,4 +3,7 @@ - \ No newline at end of file + + + + diff --git a/Snmp2Mysql/Program.cs b/Snmp2Mysql/Program.cs index 3aa356f..ad7a5f0 100644 --- a/Snmp2Mysql/Program.cs +++ b/Snmp2Mysql/Program.cs @@ -1,55 +1,70 @@ -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"); + + 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) + { + 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); + } + } + } + } + } + } +} diff --git a/Snmp2Mysql/Snmp2Mysql.csproj b/Snmp2Mysql/Snmp2Mysql.csproj index f9c5394..ef4c479 100644 --- a/Snmp2Mysql/Snmp2Mysql.csproj +++ b/Snmp2Mysql/Snmp2Mysql.csproj @@ -45,6 +45,7 @@ dependencies\SnmpSharpNet.dll +