Monitor UCCX Backup Status thru SSH
Hello,
I have a UCCX Cluster where I want to monitor the backup status. I've wrote most of the code to SSH into the system and run the command to check the backup status. The issue I'm having is being able to parse it and alarm on it correctly. Can anyone help me on parsing out these three fields.....I assume it'd need to be a Key:Value pair but not sure how to do that. And if I find "SUCCESS", how can I trigger a datapoint threshold? I assume I have to convert the SUCCESS into a 1 or 0 and alarm on that INTEGER.
def status = command_output.findAll(~/Status:\s(.*)/) { key, value -> value }
def tar_file = command_output.findAll(~/Tar Filename:\s(.*)/) { key, value -> value }
def percentage = command_output.findAll(~/Percentage Complete:\s(.*)/) { key, value -> value }
Here is my Groovy script:
<span class="pln">import com.santaba.agent.groovyapi.expect.Expect;
import com.santaba.agent.groovyapi.snmp.Snmp;
import com.santaba.agent.groovyapi.http.*;
import com.santaba.agent.groovyapi.jmx.*;
import org.xbill.DNS.*;
// import the logicmonitor expect helper class
import com.santaba.agent.groovyapi.expect.Expect;
// get the hostname and credentials from the device property table
hostname = hostProps.get("system.hostname");
userid = hostProps.get("ssh.user");
passwd = hostProps.get("ssh.pass");
// open an ssh connection and wait for the prompt
ssh_connection = Expect.open(hostname, userid, passwd);
ssh_connection.expect("admin:");
// run command
ssh_connection.send("utils disaster_recovery status backup\n");
ssh_connection.expect("admin:");
// logout from the device
ssh_connection.send("exit\n");
// collect the output, then close the ssh connection
output=ssh_connection.before();
ssh_connection.expectClose();
// Everything here below is just testing/playing with the output...this could be all wrong/bad
//===============================================================================================
// strip the info we need value and print the config
def status = output.findAll(~/Status:\s(.*)/)
def tar_file = output.findAll(~/Tar Filename:\s(.*)/)
if ( status =~ "SUCCESS" )
{
//Set code to 0 for success"
def statuscode = 0
}else{
//Set code to 1 for failure"
def statuscode = 1
}
println output;
// return with a response code that indicates we ran successfully
return(0);</span>
And here is what the Output looks like:
<span class="pln">utils disaster_recovery status backup
Status: SUCCESS :Backup Completed...
Tar Filename: 2020-11-02-02-00-01.tar
Storage Location: NETWORK
Operation: backup
Percentage Complete: 100
UCCX VOIP-UCCX-001 UCPREFS SUCCESS Mon Nov 02 02:00:01 EST 2020 activelog/platform/drf/log/2020-11-02-02-00-01_b_voip-uccx-001_uccx_ucprefs.log
UCCX VOIP-UCCX-001 PHX_RPT SUCCESS Mon Nov 02 02:00:07 EST 2020 activelog/platform/drf/log/2020-11-02-02-00-01_b_voip-uccx-001_uccx_phx_rpt.log
UCCX VOIP-UCCX-001 UCDB SUCCESS Mon Nov 02 02:00:08 EST 2020 activelog/platform/drf/log/2020-11-02-02-00-01_b_voip-uccx-001_uccx_ucdb.log
UCCX VOIP-UCCX-001 PHX_CONFIG SUCCESS Mon Nov 02 02:00:47 EST 2020 activelog/platform/drf/log/2020-11-02-02-00-01_b_voip-uccx-001_uccx_phx_config.log
UCCX VOIP-UCCX-001 TCT SUCCESS Mon Nov 02 02:00:47 EST 2020 activelog/platform/drf/log/2020-11-02-02-00-01_b_voip-uccx-001_uccx_tct.log
UCCX VOIP-UCCX-001 CDPAGT SUCCESS Mon Nov 02 02:00:48 EST 2020 activelog/platform/drf/log/2020-11-02-02-00-01_b_voip-uccx-001_uccx_cdpagt.log
UCCX VOIP-UCCX-001 SYSLOGAGT SUCCESS Mon Nov 02 02:00:48 EST 2020 activelog/platform/drf/log/2020-11-02-02-00-01_b_voip-uccx-001_uccx_syslogagt.log
UCCX VOIP-UCCX-001 PLATFORM SUCCESS Mon Nov 02 02:00:49 EST 2020 activelog/platform/drf/log/2020-11-02-02-00-01_b_voip-uccx-001_uccx_platform.log
UCCX VOIP-UCCX-001 CLM SUCCESS Mon Nov 02 02:00:51 EST 2020 activelog/platform/drf/log/2020-11-02-02-00-01_b_voip-uccx-001_uccx_clm.log
UCCX VOIP-UCCX-001 CCXCOMPONENT SUCCESS Mon Nov 02 02:00:51 EST 2020 activelog/platform/drf/log/2020-11-02-02-00-01_b_voip-uccx-001_uccx_ccxcomponent.log
UCCX VOIP-UCCX-001 REPORTER SUCCESS Mon Nov 02 02:01:25 EST 2020 activelog/platform/drf/log/2020-11-02-02-00-01_b_voip-uccx-001_uccx_reporter.log
UCCX VOIP-UCCX-001 CUIC_CONFIG SUCCESS Mon Nov 02 02:01:26 EST 2020 activelog/platform/drf/log/2020-11-02-02-00-01_b_voip-uccx-001_uccx_cuic_config.log
UCCX VOIP-UCCX-001 IDS_CONFIG SUCCESS Mon Nov 02 02:01:26 EST 2020 activelog/platform/drf/log/2020-11-02-02-00-01_b_voip-uccx-001_uccx_ids_config.log
UCCX VOIP-UCCX-002 SYSLOGAGT SUCCESS Mon Nov 02 02:01:27 EST 2020 activelog/platform/drf/log/2020-11-02-02-00-01_b_voip-uccx-002_uccx_syslogagt.log
UCCX VOIP-UCCX-002 CDPAGT SUCCESS Mon Nov 02 02:01:28 EST 2020 activelog/platform/drf/log/2020-11-02-02-00-01_b_voip-uccx-002_uccx_cdpagt.log
UCCX VOIP-UCCX-002 TCT SUCCESS Mon Nov 02 02:01:28 EST 2020 activelog/platform/drf/log/2020-11-02-02-00-01_b_voip-uccx-002_uccx_tct.log
UCCX VOIP-UCCX-002 PHX_CONFIG SUCCESS Mon Nov 02 02:01:29 EST 2020 activelog/platform/drf/log/2020-11-02-02-00-01_b_voip-uccx-002_uccx_phx_config.log
UCCX VOIP-UCCX-002 CCXCOMPONENT SUCCESS Mon Nov 02 02:01:29 EST 2020 activelog/platform/drf/log/2020-11-02-02-00-01_b_voip-uccx-002_uccx_ccxcomponent.log
UCCX VOIP-UCCX-002 PLATFORM SUCCESS Mon Nov 02 02:01:45 EST 2020 activelog/platform/drf/log/2020-11-02-02-00-01_b_voip-uccx-002_uccx_platform.log
UCCX VOIP-UCCX-002 PHX_RPT SUCCESS Mon Nov 02 02:01:46 EST 2020 activelog/platform/drf/log/2020-11-02-02-00-01_b_voip-uccx-002_uccx_phx_rpt.log
UCCX VOIP-UCCX-002 CLM SUCCESS Mon Nov 02 02:01:47 EST 2020 activelog/platform/drf/log/2020-11-02-02-00-01_b_voip-uccx-002_uccx_clm.log
UCCX VOIP-UCCX-002 REPORTER SUCCESS Mon Nov 02 02:01:47 EST 2020 activelog/platform/drf/log/2020-11-02-02-00-01_b_voip-uccx-002_uccx_reporter.log
UCCX VOIP-UCCX-002 CUIC_CONFIG SUCCESS Mon Nov 02 02:01:48 EST 2020 activelog/platform/drf/log/2020-11-02-02-00-01_b_voip-uccx-002_uccx_cuic_config.log
UCCX VOIP-UCCX-002 IDS_CONFIG SUCCESS Mon Nov 02 02:01:49 EST 2020 activelog/platform/drf/log/2020-11-02-02-00-01_b_voip-uccx-002_uccx_ids_config.log </span>
Jason_Fant
OP5 years agoAs soon as I deployed it, it found a backup failure! Thank you again!
LM User
·5 years agoEasiest problem I solved all day!
Make sure to return 0 for successful run. The collector uses that return value. It's more important in discovery, but should be there for all groovy scripts.
Jason_Fant
OP5 years agowait, nevermind! I figured it out! I can use the Date() and getTime() functions to convert the dates into seconds since 1970, and then I can compare times via a common denominator....seconds!
---GROOVY---
returns null
output:
Hello World todates date is: 2020110311
file date is: Tue Nov 03 02:02:01 EST 2020
the FileDate in seconds is: 1604386921000
Jason_Fant
OP5 years agoHey, do you think I can pick your brain some more? Next thing I wanted to stab with this output is parsing the backup date and compare to see if it's older than 24 hours. I tried to take the filename tar file and break it up and compare that against current time with the format of yyyyMMddHH. However.....I'm gonna get a lot of false alarms when this runs and I think my logic might be off....how can I convert these time values into something where I can compare to confirm it's indeed been 24+hrs since last backup. Also attached a screenshot of the script output.
Here's my new Collector script:
LM User
·5 years agoYou're welcome. It really helps when you come having done your homework and taken a stab at the script. The fact that you had the expect portion of the script already working was 90% of the work.
Jason_Fant
OP5 years agoYou sir, are the man! That fixed the script!
Thank you for helping me!!!
LM User
·5 years agoAh, closing parenthesis. The script got to } before finding the closing ) for the println statement.
Jason_Fant
OP5 years agoYa, I understand. However, I was still getting that error for splitLine[2] BEFORE I changed my WILDVALUE to be more unique.
LM User
·5 years agoThe wildvalue you define as you output from your discovery script needs to match the wildvalue output from collection. For example, your AD script outputs this:
So, your collection script has to output something like this:
This is a problem because there are more than one CDPAGT's in your instance list. WILDVALUE also needs to be unique.
You modified the discovery script to make sure the lines are unique, which is great. However, you only modified the WILDALIAS, which is only part of what needs to be unique. The WILDVALUE also needs to be unique. You can do this by changing the println in each script:
See how that creates a unique WILDVALUE and a unique WILDALIAS? Also see that the same WILDVALUE defined in discovery matches the output of collection?
Jason_Fant
OP5 years agoThanks for the help! I had to make some changes to the Discovery script as some of the lines returned are not unique. So it was having overlapping INSTANCES. To make them unique, I changed the print lines to include the actual name of the UCCX Server.
That worked but now it's throwing an error on my collection script. I attached the XML DS if you want to see what I've got.
LM User
·5 years agoYou'd setup a datapoint using the output and post-processor would be key/value pairs. The key would be:
##WILDVALUE##.status
Set a threshold for < 100 and you should be good to go.
LM User
·5 years agoBtw, this assumes BATCHSCRIPT is the collection method. This type of output won't work with SCRIPT.
LM User
·5 years agoYou don't need this bit since you're not using any of those libraries. Minuscule performance drain.
Do you have a discovery script and a collection script or is this one script as far as you got? If it is, you'll need to make two copies of your script. One that will output the instances (discovery) and one that will output the data (collection).
For both, you'll want to loop through and inspect each line of the output. You'll do this like this: