• 0
Sunny

Internal check with groovy script to telnet SMTP Port -25

Question

Hi Everyone,

I was referring to : https://www.logicmonitor.com/support/terminology-syntax/scripting-support/groovyexpect-text-based-interaction/ and there it's written a groovy script example which describes  "Telnet/Port Connectivity: Test FTP Server Availability". However, I'm specifically looking to telnet to multiple hosts over port 25 from different devices. For e.g.: let's create a DS, then in the devices [I'm going to add a multiple collectors from where I want to telnet to multiple hosts] and then the groovy script will execute and telnet to over port 25 from each of the separate collector to the specific hosts. Not sure how would I achieve this? 

Any interesting idea/suggestion/reference would be happy to listen? 

 

Thanks,
Sam

Share this post


Link to post
Share on other sites

4 answers to this question

Recommended Posts

  • 0

Are you looking for all the collectors to telnet to the same set of hosts or each collector telnet to a different set of servers? For example CollectorA would telnet to Server1 and Server2, CollectorB would telnet to Server3 and Server4, etc? If the latter, you would just add Server1, Server2, Server3 and Server4 into LogicMonitor as Resources. Then create the DataSource which telnet to port 25 on ##HOSTNAME## as coded. Then whatever collector is assigned to each server will do the actual telnet check.

Any particular thing you need to do with telnet to port 25 (smtp)? If you are just checking if the port is live or just get the version header, you might be able to clone and modify the existing "Port-" Datasource. I did not test this though.

 

Share this post


Link to post
Share on other sites
  • 0

Hi Mike,

Thank you for your reply. Yes, I'm looking to do this : "CollectorA would telnet to Server1 and Server2, CollectorB would telnet to Server3, CollectorC would telnet to Server4 and CollectorD would telnet to Server5".
Would you direct me how to do that?

Looking forward to your reply.

 

Thanks,

Sam

Share this post


Link to post
Share on other sites
  • 0

So, Server1, Server2, Server3, Server4 and Server5 already added as devices in Logicmonitor.

I've created the Datasource, under -->  In Applies to field defines which devices will be associated with this DataSource "I Should need to add Server1,2,3,4,...", right? 

And then I've made this groovy script: 
######################################################

import com.santaba.agent.groovyapi.expect.Expect;
import com.santaba.agent.groovyapi.snmp.Snmp;
import com.santaba.agent.groovyapi.jmx.*;
import org.xbill.DNS.*;

// Specify hostname, port and timeout
hostname = hostProps.get("system.hostname");
port = 25;
timeout = 30;

// initiate an connection to the host:port
smtp_connection = Expect.open(hostname, port, timeout);
smtp_connection.expect("220");
smtp_connection.send("quit\n");

// return with a response code
return(1);

#####################################################

Don't know how to test against each server from the collector. 

Would you elaborate this hostname part please? : 
Then create the DataSource which telnet to port 25 on "##HOSTNAME##" as coded.

 

Thanks,

Sam

 

Share this post


Link to post
Share on other sites
  • 0

LogicMonitor itself will take care of most of that for you and you don't normally need to worry about which collector is going to be used. Make sure that the AppliesTo covers all servers you want to check against and that is all you need to do. When you add a Device/Resource to LogicMonitor, you assign each one to a Collector or Collector ABCG. Anytime you run a check or script against that device, LogicMonitor will automatically look up what collector is assigned to it and use that collector. You don't need to tell it what collector to use each time.

Ignore what I said about ##HOSTNAME##, you have that covered by the "hostname = hostProps.get("system.hostname");" line.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.