/build/static/layout/Breadcrumb_cap_w.png

smart label on machines that haven't rebooted in 2 weeks

Is there a way in kace to find only machines that have been on for 2 weeks. I want to be able to create a smart label that finds machines that are on for more then 2 weeks and restart them. I've tried the greater than option but it appears that the uptime value in kace is a string. Here's the sql I tried and failed at:

 

 

SELECT

 

CONCAT(SUBSTRING_INDEX(UPTIME, ',', 1), ' days, ', SUBSTRING(UPTIME, LOCATE(',', UPTIME) + 1, LOCATE(':', UPTIME) - LOCATE(',', UPTIME) - 1), ' hours, ', SUBSTRING_INDEX(UPTIME, ':', -1), ' minutes') AS UPTIME,

 

REPLACE(MACHINE.USER_LOGGED,'\\','\\\\') as USER_LOGGED, NAME, IP,

 

LPAD(SUBSTRING_INDEX(UPTIME, ',', 1),3,"0") as DAYS,

 

LPAD(SUBSTRING(UPTIME, LOCATE(',', UPTIME) + 1, LOCATE(':', UPTIME) - LOCATE(',', UPTIME) - 1),3,"0") as HOURS,

 

LPAD(SUBSTRING_INDEX(UPTIME, ':', -1),3,"0") as MINUTES

 

FROM MACHINE MACHINE

 

Where datepart(dd, UPTIME) >= 14

ORDER BY DAYS, HOURS, MINUTES


0 Comments   [ + ] Show comments

Answers (1)

Posted by: Ben M 11 years ago
9th Degree Black Belt
0

SELECT MACHINE.NAME AS SYSTEM_NAME, MACHINE.IP, USER_LOGGED, LAST_REBOOT, LAST_SYNC  FROM MACHINE WHERE DateDiff(CurDate(), LAST_REBOOT) > 14 ORDER BY LAST_REBOOT

This is SQL I wrote a while back that should do what you want.


Comments:
  • Hrm... I'm not sure how to make that work on my kbox as I have multiple orgs. I'm getting an SQL syntax error when I tried,

    select MACHINE.*, C.CLIENT_CONNECTED, UNIX_TIMESTAMP(now()) - UNIX_TIMESTAMP(LAST_SYNC) as LAST_SYNC_TIME,
    UNIX_TIMESTAMP(LAST_SYNC) as LAST_SYNC_SECONDS
    from ORG2.MACHINE
    LEFT JOIN KBSYS.KUID_ORGANIZATION O ON O.KUID=MACHINE.KUID LEFT JOIN KBSYS.SMMP_CONNECTION C ON C.KUID = MACHINE.KUID AND O.ORGANIZATION_ID = 2
    where (( DateDiff(CurDate(), LAST_REBOOT) > 30 ORDER BY LAST_REBOOT))



    ERROR IS:
    mysql error: [1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY LAST_REBOOT))' at line 5] in EXECUTE( "select MACHINE.*, C.CLIENT_CONNECTED, UNIX_TIMESTAMP(now()) - UNIX_TIMESTAMP(LAST_SYNC) as LAST_SYNC_TIME, UNIX_TIMESTAMP(LAST_SYNC) as LAST_SYNC_SECONDS from ORG2.MACHINE LEFT JOIN KBSYS.KUID_ORGANIZATION O ON O.KUID=MACHINE.KUID LEFT JOIN KBSYS.SMMP_CONNECTION C ON C.KUID = MACHINE.KUID AND O.ORGANIZATION_ID = 2 where (( DateDiff(CurDate(), LAST_REBOOT) > 14 ORDER BY LAST_REBOOT))") - awingren 11 years ago
    • Nevermind, I was over-thinking it... this worked fine:

      SELECT MACHINE.NAME AS SYSTEM_NAME, MACHINE.IP, USER_LOGGED, LAST_REBOOT, LAST_SYNC FROM MACHINE WHERE DateDiff(CurDate(), LAST_REBOOT) > 30 ORDER BY LAST_REBOOT - awingren 11 years ago
      • This seems to work for a report but not for a smart label... any thoughs? - rsm11 11 years ago
      • This works fine as a smart label for me. How are you setting up the smart label? - Ben M 11 years ago

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ