Forum Discussion
5 years ago
Hey, 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:
// 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:"); // enter enable mode 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(); // now lets process the output output.eachLine{ line -> // let's turn this: // 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 // into this: // [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] // This lets us address each bit individually. def splitLine = line.tokenize(" ") // in our collection script, we'd add a line to our loop that checks for "percentage complete" like this: // [Status:, SUCCESS, :Backup, Completed...] if (splitLine[0] == "Status:"){ println("Overall.status:" + ((splitLine[1] == "SUCCESS")? 0:1)) } if (splitLine[1] == "Filename:"){ // take the tar file name and break it up so we can compare date with Current Time. // [2020, 11, 02, 02, 00, 01.tar] // We can then combine yyyyMMddHHmm and see if that's greater than current time for MMddHHmm // [2020110302 <= 20201103] def tarFileDate = splitLine[2].tokenize("-"); def date=new Date().format('yyyyMMddHH'); if ((tarFileDate[0] + tarFileDate[1] + tarFileDate[2] + tarFileDate[3]) < date){ // TRUE println("currentdate.date: " + date); }else{ // FALSE println("date.date: " + 0); } } if (splitLine[0] == "UCCX"){ // for data collection, we need to output WILDVALUE.status: 1 // splitLine[2] contains our WILDVALUE // [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] // (we defined wildvalue as the first term of the discovery output) println(splitLine[1] + "::" + splitLine[2] + ".status: " + ((splitLine[3] == "SUCCESS")? 0:1)) // the last bit checks that term 3 in our split output contains "SUCCESS". // if it does, let's output 0, if not let's output 1 } } // return with a response code that indicates we ran successfully return(0);
Related Content
- 2 years ago
- 4 months ago