C# monitor SNMP timeticks from multiple IP addresses - c#

I'm attempting to monitor multiple SNMP agents (timeticks) with SnmpSharpNet across separate networks. The code below works with a single IP address, but when I try and connect to a second IP address the code fails, I'm trying to run this asynchronously but it appears that SnmpSharpNet won't allow me to receive data from more than one agent.
Is this the right way to approach this problem? Is there a better alternative to SmnpSharpNet?
community = new OctetString("public");
// Define agent parameters class
param = new AgentParameters(community);
// Set SNMP version to 1 (or 2)
param.Version = SnmpVersion.Ver1;
for (int i = 0; i < sendsqldatalist.Count(); i++)
{
agent = new IpAddress(sendsqldatalist[i].ip);
target = new UdpTarget((IPAddress)agent, 161, 2000, 1);
// Make SNMP request
resultlist.Add(result = (SnmpV1Packet)target.Request(pdu, param));
// If result is null then agent didn't reply or we couldn't parse the reply.r
if (resultlist[i] != null)
{
// ErrorStatus other then 0 is an error returned by
// the Agent - see SnmpConstants for error definitions
if (resultlist[i].Pdu.ErrorStatus != 0)
{
Console.WriteLine("error on - " + sendsqldatalist[i].oid + " " + sendsqldatalist[i].ip);
// agent reported an error with the request
//- Error status found here http://www.docs.snmpsharpnet.com/docs-0-9-1/
MessageBox.Show("Error in SNMP reply from " + target.Address.ToString() + Environment.NewLine + "Error status " + result.Pdu.ErrorStatus.GetType() + Environment.NewLine + "Error Index " + result.Pdu.ErrorIndex.ToString(), "WARNING!");
}
else
{
Console.WriteLine("ConnectSNMP() CONNECTED - " + sendsqldatalist[i].oid + " - " + sendsqldatalist[i].ip);
}
}
}
Thanks in advance!

Related

How to load a data in asp Grid View one by one exactly after inserted into the database?

I have a method called processPayment, which usually does the processing job of each client to their banking provider and write a log into the database. It works smoothly until there are more than 20 records to charge and it crashed saying timeout issues. I lost my mind here I did take a snap on my timer it will run till 2 Minutes but I provided the Timeout command for 5 Minutes. And still doesn't work.
I wonder is there any chances to show log records in the grid at the same time it processing job to the bank?
I have written a log of every transaction like this:
I think this is because of the timeout so I want to keep my connection open until is finished the whole payment process. I believe by writing one by one in gird helps me to open my connection all the time and maybe that will resolve my issue.
Another thing that needs to keep in mind is:
I am trying to connect from Azure (Payment Job System is running on
the Azure) to AWS (CRM System is running on AWS in a different
location). I need to connect to the CRM System in order to get the
customer details and update their purchase order and receipt and many
more.
My Method have:
for (int i = 0; i < JobCount; i++)
{
var items = csvLists[i];
Page.ClientScript.RegisterStartupScript(this.GetType(), "ShowMessage", string.Format("<script type='text/javascript'>alert('{0}')</script>", "The Payment is being proceed for : " + items["First Name"] + " " + items["Last Name"]));
var paymentId = items["Payment Id"];
var clientId = items["Client Id"];
var client = items["Client Name"];
var amount = items["Total Payment Amount"];
var method = items["Payment Method"];
AddLog(finalJobId, taskId, "Sending payment #" + i + "- Client: " + client + " - PaymentId: " + paymentId + " - Amount: " + amount + " - Payment Method: " + method);
//Process Actual Payment Options with Details
var task = ProcessPayment.Process(int.Parse(clientId), int.Parse(paymentId), serverValue);
AddLog(finalJobId, taskId, "Received Response #" + i + " - Client: " + client + " - PaymentId: " + paymentId + " - Amount: " + amount + " - Payment Method: " + method + " - Result: " + task.Result.Response);
}
ShowLog(finalJobId, taskId);
public void ShowLog(int jobId, int taskId)
{
if (jobId <= 0) return;
var result = DBTools.Tools().Helper.GetJobActivityByJobId(jobId);
grdloadproperties.DataSource = result;
grdloadproperties.DataBind();
}

Problem with consumer.receive MessageSelector

I have a problem in activemq. I want to receive a special message from my activemq queue. I have there over 300 Messages, and I want one of the message. I solved this with a multiselectcombobox. In this box I have all messages with all properties I need.
When I click on the 247 item, I want do select the item to receive the message, after them I want to send the message but first I have a problem with the receive.
I don't know why it doesn't work. Maybe someone has an idea?
ErrorMessageProperty prop = new ErrorMessageProperty();
IMessage message = null;
try
{
string MsgID = MSGID;
string desinationque = sourceQueue;
string selector = "ProducerId = '" + MsgID + "'";
IDestination dest = MQSession.GetDestination(desinationque);
Uri _activeMQURI = new Uri(conf.ActiveMqURL);
MQConnectionFactory = new NMSConnectionFactory(_activeMQURI);
using (MQConnection = MQConnectionFactory.CreateConnection(conf.ActiveMqUser, conf.ActiveMqPWD))
using (MQSession = MQConnection.CreateSession(AcknowledgementMode.AutoAcknowledge))
{
try
{
MQConnection.Start();
}
catch (Exception ex)
{
myLogger.NLogger.Info("MQReceiveTextMessage Connection fehlgeschlagen: " + ex.Message);
}
using (IMessageConsumer consumer = this.MQSession.CreateConsumer(dest, selector,false))
{
if (shallwait)
{
try
{
message = consumer.Receive();
}
catch (Exception ex)
{
myLogger.NLogger.Error("Error in consumer Receive (MQReceiveTextMessage): Message" + message + " Fehler-Exception: " + ex.Message);
}
}
else
{
message = consumer.Receive(TimeSpan.FromSeconds(1));
}
}
}
}
catch (Exception ex)
{
myLogger.NLogger.Error("Error in MQReceiveTextMessage: Parameter: sourceQueue: " + sourceQueue + " MSGID: " + MSGID + " Message: " + message + " Fehler-Exception: " + ex.Message);
}
return message;
}
My ProducerID is correct. But why doesn't this work? It stops at the line
message = consumer.receive();
I don't know anymore
With the selector ProducerId = 'MsgIDValue', the operation consumer.receive() is searching a Message in the queue with a custom property "ProducerId" with the value of the variable MsgID. If the message is not found the consumer waits new messages.
If you want to search for a default message field, message header field references are restricted to JMSDeliveryMode, JMSPriority, JMSMessageID, JMSTimestamp, JMSCorrelationID, and JMSType. JMSMessageID, JMSCorrelationID, and JMSType values may be null and if so are treated as a NULL value.
Source Message Selectors
I used Apache.NMS and Apache.NMS.ActiveMQ (1.7.1.3924)
is it possible to u se this api than the jms?
I try this since 1 Week and the selector does'nt work....
Maybe someone othe

OrientDB Query works sometimes and at other times throws FormatException

I'm having a problem with this query below. I'm connecting to OrientDB using the C# driver and running the query in my c# code. All this code is in a loop and the queries in the try block works for a number of iterations and afterwards fails throwing a FormatException. At the point it fails I copy out the query and run it in the orientDB web interface and it returns the expect records so I'm sure it's not the input. So I'm so confused as to why it succeeds sometimes and fails at other times even when the input string is correct. Has anyone encountered a similar problem? Someone please help.
string origin = route[i].Trim();
string destination = route[i + 1].Trim();
List<ODocument> document = new List<ODocument>();
try
{
document = database.Query("select from (traverse out_Connects from " + origin + ") where in = " + destination);
//document = database.Query("select from Connects where (out = " + origin + " and in = " + destination + ")");
}
catch (Exception e)
{
//document = database.Query("select from Connects where (out = " + origin + " and in = " + destination + ")");
}

How to use DirectoryEntry("IIS://Localhost/W3SVC") to change IP address with several host header entries

I'm trying to programmatically change the IP of a website running on Server 2003.
When I run the following code, the site binding itself gets changed, but there are other host header values that need to be changed. How do I change those?
protected static void ChangeServerIP(string old_ip, string new_ip)
{
int siteChangedCount = 0;
DirectoryEntry entry = new DirectoryEntry("IIS://LocalHost/W3SVC");
if (entry != null)
{
foreach (DirectoryEntry site in entry.Children)
{
if (site.SchemaClassName == "IIsWebServer")
{
Console.WriteLine("Server Binding: " + site.Properties["ServerBindings"][0].ToString());
if (site.Properties["ServerBindings"][0].ToString().Contains(old_ip))
{
string ServerComment = site.Properties["ServerComment"].Value.ToString();
Console.WriteLine("Changing " + ServerComment + "'s IP address from " + old_ip + " to " + new_ip);
site.Properties["ServerBindings"].Value = site.Properties["ServerBindings"][0].ToString().Replace(old_ip, new_ip);
site.CommitChanges();
siteChangedCount++;
Console.WriteLine("New IP address bound to site: " + ServerComment + " IP: " + site.Properties["ServerBindings"].Value.ToString());
}
}
}
}
}
Did you try assigning the value to the first item in the PropertyValueCollection?
site.Properties["ServerBindings"][0].Value = site.Properties["ServerBindings"][0].ToString().Replace(old_ip, new_ip);

Exchange Server Error: The remote server returned an error: (440) Login Timeout

I'm creating a window based program to retrieve emails in Exchange Server 2003 using webDAV.
im getting the error on loResponse = (HttpWebResponse)loRequest.GetResponse();
Here's the code:
lsRootUri = p_strServer + "/Exchange//" + p_strAlias + "//" + p_strInboxURL + "//";
lsQuery = "<?xml version=\"1.0\"?>"
+ "<D:searchrequest xmlns:D = \"DAV:\" xmlns:m=\"urn:schemas:httpmail:\">"
+ "<D:sql>SELECT \"urn:schemas:httpmail:hasattachment\", \"DAV:displayname\", "
+ "\"urn:schemas:httpmail:from\", \"urn:schemas:httpmail:subject\", "
+ "\"urn:schemas:httpmail:htmldescription\" FROM \"" + lsRootUri
+ "\" WHERE \"DAV:ishidden\" = false "
+ "AND \"DAV:isfolder\" = false "
+ "AND \"urn:schemas:httpmail:hasattachment\" = true "
+ "AND \"urn:schemas:httpmail:read\" = false"
+ "</D:sql></D:searchrequest>";
loRequest = (HttpWebRequest)WebRequest.Create(lsRootUri);
loRequest.Credentials = new NetworkCredential(p_strUserName, p_strPassword);
loRequest.Method = "SEARCH";
laBytes = System.Text.Encoding.UTF8.GetBytes(lsQuery);
loRequest.ContentLength = laBytes.Length;
loRequestStream = loRequest.GetRequestStream();
loRequestStream.Write(laBytes, 0, laBytes.Length);
loRequestStream.Close();
loRequest.ContentType = "text/xml";
loRequest.Headers.Add("Translate", "F");
loResponse = (HttpWebResponse)loRequest.GetResponse();
loResponseStream = loResponse.GetResponseStream();
loXmlDoc.Load(loResponseStream);
loResponseStream.Close();
i remove the domain name from the user name and it is now working...
There are various things that could be going wrong here:
You can't establish a connection to the actual server.
You can't establish a connection to the mail server.
I'd check that the network credentials you have are valid and give you the access you need.
Something else that's just sprung to mind is to check that you're trying to connect on the correct port. Connecting interactively will do this as the programs you use will have the ports set up, however in your program you'll need to set the port. The server could be set up to reject connections on the "wrong" ports.

Categories