Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // LT Scrape File
- // This is to scrape from LT and dump it into the Meteor DB only.
- //Requjred to Connect to mysql server
- var mysql = require('mysql');
- //Underscore for Parsing
- var _ = require('underscore');
- //Access local mongodb
- var MeteorDB = require('meteordb');
- //Main Obj
- var LTScrape = {};
- //Create mysql connection
- LTScrape.Connect = mysql.createConnection({
- host: '172.16.5.6',
- user: 'mkozak',
- password: 'Mk1290!@',
- database: 'labtech'
- });
- //This, when initialized, will run a single scrape and store each item in the DB.
- LTScrape.Initialize = function(callback) {
- //Reach out to the MeteorDB and determine what tickets we should scrape from LT based off of last highest ticket stored.
- MeteorDB.getHighestTicket(function(data) {
- //Create our SQL query to scrape data from LT
- var sql = 'SELECT * FROM tickets WHERE TicketID > ' + data.TicketID + ' AND Status < 4 LIMIT 100';
- LTScrape.Connect.query(sql, function(error, results, fields) {
- //If there's no new tickets, return.
- if (results.length === 0) {
- callback("there is no new tickets");
- return;
- }
- //Process Tickets
- var highestTicket = "";
- _.each(results, function(i) {
- //Update Highest Ticket Result
- if (i.TicketID > highestTicket) {
- highestTicket = i.TicketID;
- MeteorDB.newHighestTicket(highestTicket);
- }
- //Create Ticket Data for Storage
- var link = '<a href=\"labtech:open?computerid=' + i.ComputerID + '\">Link to Computer in Labtech<\/a>';
- var postData = {
- "helpdesk_ticket": {
- "description_html": link,
- "subject": "LT#" + i.TicketID + ": " + i.Subject,
- "email": "blackhole@meteormanaged.com",
- "priority": 1,
- "status": 2,
- "source": 2,
- "ticket_type": "Incident",
- "group_id": "1000190464"
- }
- };
- //Store the Ticket
- MeteorDB.storeTicket(postData.helpdesk_ticket, function(response) {
- callback(response);
- });
- });
- });
- });
- };
- module.exports = LTScrape;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement