Scripts

Is there a way to access the info that is available for each device so as to make a script that monitors the system uptime and generates a ticket if system has been on for 30 days or more? I have already wrote a procedure that I can run and it will find last boot time and figure out how many days system has been on and if more than 30 will use the email trigger to generate a ticket but i have only gotten it to show the device name. So is there a way I can add the client info in the ticket much like it does when a procedure fails? hope this makes sense.

Is there a way to have a procedure use an alert for when it succeeds? That would make this a lot simpler lol :slight_smile:

Hello @ertonemad ,

We have forwarded both queries to the development team and we will get back to you with additional information as soon as possible.

Do they make sense as to what I am trying to do or access?

Hello @ertonemad ,

import os;
result=os.popen(‘systeminfo | find “System Boot Time:”’).read();
print(result);

will show you the System boot time (for ex: System Boot Time: 9/7/2016, 4:35:30 AM)

I believe you’ve figured that one out already, based on your initial post.
However in order to determine if it was up for more then X days, we need to subtract that date and time from the current date and time, convert into minutes and then into days. After that with a series of ifs, determine if the resulted value is higher then X, and trigger an alert.
We do not have that implemented. At the moment, an alert is triggered only if a Procedure fails.

Please allow us some time to figure this one out.

Here’s what I have now:
import datetime as dt
import socket
import smtplib
import subprocess;
process = subprocess.Popen(‘wmic os get lastbootuptime’,stdout=subprocess.PIPE);
result = process.communicate()[0]
postString = result.split("
“,1)[1];
byear = postString[0:4]
bmonth = postString[4:6]
bday = postString[6:8]
bdate = bmonth + ‘/’ + bday + ‘/’ + byear
cdate = dt.date.today().strftime(”%m/%d/%Y")
date_format = “%m/%d/%Y”
a = dt.datetime.strptime(bdate, date_format)
b = dt.datetime.strptime(cdate, date_format)
delta = b - a
days = delta.days
host = socket.gethostname()
cname = host.upper()
if days >= 30:
to = ‘support@xxxxxxxxxxxx.com’
gmail_user = ‘xxxxxx@gmail.com’
gmail_pwd = ‘xxxxxxxxx’
smtpserver = smtplib.SMTP(“smtp.gmail.com”,587)
smtpserver.ehlo()
smtpserver.starttls()
smtpserver.ehlo
smtpserver.login(gmail_user, gmail_pwd)
header = ‘To:’ + to + ’
’ + 'From: ’ + gmail_user + ’
’ + 'Subject:Reboot Needed

print header
msg = header + "
Machine " + cname + " has not had a reboot in 30 days.

"
smtpserver.sendmail(gmail_user, to, msg)
print ‘done!’
smtpserver.close()
else:
print “Machine " + cname + " does not need a reboot.”

So my issue now is that I’d like to be able to pull client info/owner info for the particular machine (like when a monitor fails the device info that gets attached to ticket/alert)

Hello @ertonemad ,

We have contacted you over email to discuss this further.

We would be interested in such a script / function as we like to make sure our servers do reboot every week

you can request any type of Script and we will write it for you for free.

Can you please put you request in the relevant thread. thanks.

Hello @StrobeTech ,

We have contacted you by email regarding this request to get more details. Thank you for the feedback.