Advertisement
department_g33k

Spiceworks Ticket Grabber

Feb 7th, 2012
479
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 4.03 KB | None | 0 0
  1. #include <GUIConstantsEx.au3>
  2. #include <SQLite.au3>
  3. #include <SQLite.dll.au3>
  4. #include <string.au3>
  5.  
  6.  
  7. ;-VARIABLES TO UNCOMMENT FOR PRODUCTION -------------------------------------------------
  8. $DBPath = "C:\Program Files\Spiceworks\db\" ;PROD:: For Production Use
  9. $OutputPath = @ScriptDir & "\"  ;PROD:: For Production Use
  10. ;-VARIABLES TO UNCOMMENT FOR DEBUGGING --------------------------------------------------
  11. ;~ $OutputPath = "C:\Documents and Settings\all users\Desktop\"  ;DEBUG:: For Debugging
  12. ;~ $DBPath = "\\spiceworks-server\c$\program files\spiceworks\db\" ;DEBUG:: For Debugging
  13.  
  14. ;-VARIABLES TO LEAVE UNCHANGED ----------------------------------------------------------
  15. $DBFilename = "spiceworks_prod.db"
  16. $hQuery = 1
  17. $LastRunMinutes = 0
  18. Dim $ResultRow[15] = ["1", "2"]
  19. ;----------------------------------------------------------------------------------------
  20.  
  21. ;This is the timekeeper & runner script.  Be careful when changing! ---------------------
  22. While 1
  23. If @MIN <> $LastRunMinutes Then
  24. UpdateTicketDetails()
  25. $LastRunMinutes = @MIN
  26. EndIf
  27. MouseMove(@DesktopWidth,@DesktopHeight,30)
  28. Sleep(60000)
  29. WEnd
  30. ;----------------------------------------------------------------------------------------
  31.  
  32. Func UpdateTicketDetails()
  33. $TicketCount = FileOpen($OutputPath & "ticketcount.txt",2)
  34. $TicketDetail = FileOpen($OutputPath & "ticketdump.txt",2)
  35. $StartupCall = _SQLite_Startup()
  36. $SWDB = _SQLite_Open($DBPath & $DBFilename, 0x01)
  37.  
  38. ;This is total ticket count
  39. _SQLite_Query($SWDB, "SELECT COUNT(*) AS TicketCount FROM tickets WHERE status <> 'closed'", $hQuery)
  40. If @Error Then
  41.     ConsoleWrite("Query: @Error = " & @Error&@CRLF&"@Extended = "&@Extended&@CRLF)
  42. EndIf
  43.  
  44. While _SQLite_FetchData($hQuery, $ResultRow) = $SQLITE_OK
  45.     FileWriteLine($TicketCount, "Total: <"&$ResultRow[0]&">")
  46. WEnd
  47. ;Low Priority
  48. _SQLite_Query($SWDB, "SELECT COUNT(*) AS TicketCount FROM tickets WHERE status <> 'closed' AND priority = 3", $hQuery)
  49. If @Error Then
  50.     ConsoleWrite("Query: @Error = " & @Error&@CRLF&"@Extended = "&@Extended&@CRLF)
  51. EndIf
  52.  
  53. While _SQLite_FetchData($hQuery, $ResultRow) = $SQLITE_OK
  54.     FileWriteLine($TicketCount, "Hold: <"&$ResultRow[0]&">")
  55. WEnd
  56. ;Normal Priority
  57. _SQLite_Query($SWDB, "SELECT COUNT(*) AS TicketCount FROM tickets WHERE status <> 'closed' AND priority = 2", $hQuery)
  58. If @Error Then
  59.     ConsoleWrite("Query: @Error = " & @Error&@CRLF&"@Extended = "&@Extended&@CRLF)
  60. EndIf
  61.  
  62. While _SQLite_FetchData($hQuery, $ResultRow) = $SQLITE_OK
  63.     FileWriteLine($TicketCount, "Normal: <"&$ResultRow[0]&">")
  64. WEnd
  65. ;High Priority
  66. _SQLite_Query($SWDB, "SELECT COUNT(*) AS TicketCount FROM tickets WHERE status <> 'closed' AND priority = 1", $hQuery)
  67. If @Error Then
  68.     ConsoleWrite("Query: @Error = " & @Error&@CRLF&"@Extended = "&@Extended&@CRLF)
  69. EndIf
  70.  
  71. While _SQLite_FetchData($hQuery, $ResultRow) = $SQLITE_OK
  72.     FileWriteLine($TicketCount, "High: <"&$ResultRow[0]&">")
  73. WEnd
  74. FileClose($TicketCount)
  75. $TicketsTxt = FileOpen($OutputPath & "ticketdump.txt",2)
  76.  
  77. _SQLite_Query($SWDB, "SELECT * FROM tickets WHERE status <>'closed'", $hQuery)
  78. If @Error Then
  79. ConsoleWrite("@Error = " & @Error&@CRLF&"@Extended = "&@Extended&@CRLF)
  80. EndIf
  81. #cs
  82. $ResultRow[0] = Ticket Number
  83. $ResultRow[1] = Summary of Ticket
  84. $ResultRow[2] = Ticket Status
  85. $ResultRow[3] = Full Text of Ticket
  86. $ResultRow[4] = Ticket Priorty (3 = Hold, 2 = Normal 1 = High)
  87. $ResultRow[5] = Time Spent on Ticket
  88. $ResultRow[6] = Due Date
  89. $ResultRow[7] = Ticket Creation Date
  90. $ResultRow[8] = Ticket Last Updated Date
  91. $ResultRow[9] = Ticket Close Date
  92. $ResultRow[10]= Created By
  93. $$ResultRow[11]=Assigned to
  94. #ce
  95.  
  96. While _SQLite_FetchData($hQuery, $ResultRow) = $SQLITE_OK
  97.     ConsoleWrite("Ticket # "&$ResultRow[0]&"|"&$ResultRow[1]&"|"&$ResultRow[2]&"|"&$ResultRow[4]&"|"&$ResultRow[7]&"|"&$ResultRow[8]&"|"&$ResultRow[10]&"|"&$ResultRow[11]&@CRLF)
  98.     FileWriteLine($TicketsTxt, "sol|"&$ResultRow[0]&"|"&$ResultRow[1]&"|"&$ResultRow[2]&"|"&$ResultRow[4]&"|"&$ResultRow[7]&"|"&$ResultRow[8]&"|"&$ResultRow[10]&"|"&$ResultRow[11]&"-tech|eol")
  99. WEnd
  100. FileClose($TicketsTxt)
  101. _SQLite_Shutdown()
  102. EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement