Exemplo n.º 1
0
    def process_result(self, result, purchases):
        data = {}

        for item in result:

            if item['type'] is None:
                continue

            data.clear()
            serial = item['sn']

            if self.order_no == 'common':
                order_no = self.common
            else:
                order_no = self.generate_random_order_no()

            data.update({'order_no': order_no})
            data.update({'completed': 'yes'})
            data.update({'vendor': 'HP'})
            data.update({'line_device_serial_nos': serial})
            data.update({'line_type': 'contract'})
            data.update({'line_item_type': 'device'})
            data.update({'line_completed': 'yes'})

            start_date = item['startDate'].split('T')[0]
            end_date = item['endDate'].split('T')[0]

            data.update({'line_start_date': start_date})
            data.update({'line_end_date': end_date})
            data.update({'line_contract_type': item['type']})

            try:
                # There's a max 32 character limit
                # on the line service type field in Device42 (version 10.2.1)
                service_level_description = left(item['serviceLevel'], 32)
                data.update({'line_service_type': service_level_description})
            except:
                pass

            # update or duplicate? Compare warranty dates by serial, contract_id and end date
            hasher = serial + start_date + end_date

            try:
                d_start, d_end = purchases[hasher]
                # check for duplicate state
                if d_start == start_date and d_end == end_date:
                    print '\t[!] Duplicate found. Purchase ' \
                          'for SKU "%s" with end date "%s" ' \
                          'is already uploaded' % (serial, end_date)
            except KeyError:
                self.d42_rest.upload_data(data)
                data.clear()
Exemplo n.º 2
0
    def process_result(self, result, purchases):
        global full_serials
        data = {}

        for item in result:
            try:
                warranties = item['entitlements']
            except IndexError:
                if self.debug:
                    try:
                        msg = str(result['InvalidFormatAssets']['BadAssets'])
                        if msg:
                            print '\t\t[-] Error: Bad asset: %s' % msg
                    except Exception as e:
                        print e

            else:
                if self.order_no == 'common':
                    order_no = self.common
                else:
                    order_no = self.generate_random_order_no()

                serial = item['serviceTag']

                # We need check per warranty service item
                for sub_item in warranties:
                    data.clear()

                    try:
                        if 'shipDate' in item:
                            ship_date = item['shipDate'].split('T')[0]
                        else:
                            ship_date = None
                    except AttributeError:
                        ship_date = None

                    data.update({'order_no': order_no})

                    if ship_date:
                        data.update({'po_date': ship_date})

                    data.update({'completed': 'yes'})

                    data.update({'vendor': 'Dell Inc.'})
                    data.update(
                        {'line_device_serial_nos': full_serials[serial]})
                    data.update({'line_type': 'contract'})
                    data.update({'line_item_type': 'device'})
                    data.update({'line_completed': 'yes'})

                    line_contract_id = sub_item['itemNumber']

                    data.update({'line_notes': line_contract_id})
                    data.update({'line_contract_id': line_contract_id})

                    # Using notes as well as the Device42 API doesn't give back the line_contract_id,
                    # so notes is now used for identification
                    # Mention this to device42

                    contract_type = 'Service'  # default contract type

                    if 'serviceLevelDescription' in sub_item:
                        if sub_item['serviceLevelDescription'] is not None:
                            if 'Parts' in sub_item[
                                    'serviceLevelDescription'] or 'Onsite' in sub_item[
                                        'serviceLevelDescription']:
                                contract_type = 'Warranty'
                        else:  # service level description is null, continue to next entitlement item
                            continue
                    else:  # service level description not listed in entitlement, continue to next item
                        continue

                    data.update({'line_contract_type': contract_type})

                    try:
                        # There's a max 64 character limit on the line service type field in Device42 (version 13.1.0)
                        service_level_description = left(
                            sub_item['serviceLevelDescription'], 64)
                        data.update(
                            {'line_service_type': service_level_description})
                    except KeyError:
                        pass

                    # start date and end date may be missing from payload so it is only posted when both have values
                    try:
                        start_date = sub_item['startDate'].split('T')[0]
                        end_date = sub_item['endDate'].split('T')[0]
                        data.update({'line_start_date': start_date})
                        data.update({'line_end_date': end_date})
                    except AttributeError:
                        if self.debug:
                            print(
                                '[Alert]: SN:', serial,
                                ': Missing start and end date for a listed entitlement'
                            )
                            print(left(sub_item['serviceLevelDescription'],
                                       64))
                        continue

                    # update or duplicate? Compare warranty dates by serial, contract_id, start date and end date
                    hasher = serial + line_contract_id + start_date + end_date

                    try:
                        d_purchase_id, d_order_no, d_line_no, d_contractid, d_start, d_end, forcedupdate = purchases[
                            hasher]

                        if forcedupdate:
                            data['purchase_id'] = d_purchase_id
                            data.pop('order_no')
                            raise KeyError

                        # check for duplicate state
                        if d_contractid == line_contract_id and d_start == start_date and d_end == end_date:
                            print '\t[!] Duplicate found. Purchase ' \
                                  'for SKU "%s" and "%s" with end date "%s" ' \
                                  'order_id: %s and line_no: %s' % (serial, line_contract_id, end_date, d_purchase_id, d_line_no)

                    except KeyError:
                        self.d42_rest.upload_data(data)
                        data.clear()
Exemplo n.º 3
0
    def process_result(self, result, purchases):
        global full_serials
        data = {}

        if 'AssetWarrantyResponse' in result:
            for item in result['AssetWarrantyResponse']:
                try:
                    warranties = item['AssetEntitlementData']
                    asset = item['AssetHeaderData']
                    product = item['ProductHeaderData']
                except IndexError:
                    if self.debug:
                        try:
                            msg = str(
                                result['InvalidFormatAssets']['BadAssets'])
                            if msg:
                                print '\t\t[-] Error: Bad asset: %s' % msg
                        except Exception as e:
                            print e

                else:
                    if self.order_no == 'vendor':
                        order_no = asset['OrderNumber']
                    elif self.order_no == 'common':
                        order_no = self.common
                    else:
                        order_no = self.generate_random_order_no()

                    serial = asset['ServiceTag']
                    customernumber = asset['CustomerNumber']
                    country = asset['CountryLookupCode']
                    '''
                    For future implementation of registering the purchase date as a lifecycle event
                    Add a lifecycle event for the system
                    data.update({'date':ship_date})
                    data.update({'type':'Purchased'})
                    data.update({'serial_no':serial})
                    d42.upload_lifecycle(data)
                    data.clear()
                    '''

                    # We need check per warranty service item
                    for sub_item in warranties:
                        data.clear()
                        ship_date = asset['ShipDate'].split('T')[0]
                        try:
                            product_id = product['ProductId']
                        except:
                            product_id = 'notspecified'

                        data.update({'order_no': order_no})
                        if ship_date:
                            data.update({'po_date': ship_date})
                        data.update({'completed': 'yes'})

                        data.update({'vendor': 'Dell Inc.'})
                        data.update(
                            {'line_device_serial_nos': full_serials[serial]})
                        data.update({'line_type': 'contract'})
                        data.update({'line_item_type': 'device'})
                        data.update({'line_completed': 'yes'})

                        line_contract_id = sub_item['ItemNumber']
                        data.update({'line_notes': line_contract_id})
                        data.update({'line_contract_id': line_contract_id})

                        # Using notes as well as the Device42 API doesn't give back the line_contract_id,
                        # so notes is now used for identification
                        # Mention this to device42

                        service_level_group = sub_item['ServiceLevelGroup']
                        if service_level_group == -1 or service_level_group == 5 or service_level_group == 8 or service_level_group == 99999:
                            contract_type = 'Warranty'
                        elif service_level_group == 8 and 'compellent' in product_id:
                            contract_type = 'Service'
                        elif service_level_group == 11 and 'compellent' in product_id:
                            contract_type = 'Warranty'
                        else:
                            contract_type = 'Service'
                        data.update({'line_contract_type': contract_type})
                        if contract_type == 'Service':
                            # Skipping the services, only want the warranties
                            continue

                        try:
                            # There's a max 64 character limit on the line service type field in Device42 (version 13.1.0)
                            service_level_description = left(
                                sub_item['ServiceLevelDescription'], 64)
                            data.update({
                                'line_service_type':
                                service_level_description
                            })
                        except:
                            pass

                        start_date = sub_item['StartDate'].split('T')[0]
                        end_date = sub_item['EndDate'].split('T')[0]

                        data.update({'line_start_date': start_date})
                        data.update({'line_end_date': end_date})

                        # update or duplicate? Compare warranty dates by serial, contract_id, start date and end date
                        hasher = serial + line_contract_id + start_date + end_date
                        try:
                            d_purchase_id, d_order_no, d_line_no, d_contractid, d_start, d_end, forcedupdate = purchases[
                                hasher]

                            if forcedupdate:
                                data['purchase_id'] = d_purchase_id
                                data.pop('order_no')
                                raise KeyError

                            # check for duplicate state
                            if d_contractid == line_contract_id and d_start == start_date and d_end == end_date:
                                print '\t[!] Duplicate found. Purchase ' \
                                      'for SKU "%s" and "%s" with end date "%s" ' \
                                      'order_id: %s and line_no: %s' % (serial, line_contract_id, end_date, d_purchase_id, d_line_no)

                        except KeyError:
                            self.d42_rest.upload_data(data)
                            data.clear()
Exemplo n.º 4
0
    def process_result(self, result, purchases):
        global full_serials
        data = {}

        for item in result:

            if item['type'] is None:
                print 'Skip serial #: %s ( no "warranty type", probably expired )' % item[
                    'sn']
                continue

            data.clear()
            serial = item['sn']

            if self.order_no == 'common':
                order_no = self.common
            else:
                order_no = self.generate_random_order_no()

            data.update({'order_no': order_no})
            data.update({'completed': 'yes'})
            data.update({'vendor': 'HP'})
            data.update({'line_device_serial_nos': full_serials[serial]})
            data.update({'line_type': 'contract'})
            data.update({'line_item_type': 'device'})
            data.update({'line_completed': 'yes'})

            start_date = item['startDate'].split('T')[0]
            end_date = item['endDate'].split('T')[0]

            data.update({'line_start_date': start_date})
            data.update({'line_end_date': end_date})
            data.update({'line_contract_type': item['type']})

            try:
                # There's a max 64 character limit on the line service type field in Device42 (version 13.1.0)
                service_level_description = left(
                    sub_item['ServiceLevelDescription'], 64)
                data.update({'line_service_type': service_level_description})
            except:
                pass

            # update or duplicate? Compare warranty dates by serial, contract_id and end date
            hasher = serial + start_date + end_date

            try:
                d_purchase_id, d_order_no, d_line_no, d_contractid, d_start, d_end, forcedupdate = purchases[
                    hasher]

                if forcedupdate:
                    data['purchase_id'] = d_purchase_id
                    data.pop('order_no')
                    raise KeyError

                # check for duplicate state
                if d_start == start_date and d_end == end_date:
                    print '\t[!] Duplicate found. Purchase ' \
                          'for SKU "%s" with end date "%s" ' \
                          'is already uploaded' % (serial, end_date)
            except KeyError:
                self.d42_rest.upload_data(data)
                data.clear()
Exemplo n.º 5
0
    def process_result(self, result, purchases):
        data = {}

        for item in result:

            if 'BaseWarranties' in item and len(item['BaseWarranties']) > 0:
                warranties = item['BaseWarranties']
            else:
                continue

            data.clear()
            serial = item['Serial']

            if self.order_no == 'common':
                order_no = self.common
            else:
                order_no = self.generate_random_order_no()

            data.update({'order_no': order_no})
            data.update({'completed': 'yes'})

            if self.vendor == 'ibm':
                data.update({'vendor': 'IBM'})
            else:
                data.update({'vendor': 'LENOVO'})

            data.update({'line_device_serial_nos': serial.split('.')[0]})
            data.update({'line_type': 'contract'})
            data.update({'line_item_type': 'device'})
            data.update({'line_completed': 'yes'})

            lines = []

            for warranty in warranties:

                start_date = warranty['Start']['UTC'].split('T')[0]
                end_date = warranty['End']['UTC'].split('T')[0]

                data.update({'line_start_date': start_date})
                data.update({'line_end_date': end_date})
                data.update({'line_contract_type': warranty['Origin']})

                try:
                    # There's a max 64 character limit on the line service type field in Device42 (version 13.1.0)
                    service_level_description = left(
                        sub_item['ServiceLevelDescription'], 64)
                    data.update(
                        {'line_service_type': service_level_description})
                except:
                    pass

                # update or duplicate? Compare warranty dates by serial, contract_id and end date
                hasher = serial.split('.')[0] + start_date + end_date

                try:
                    d_purchase_id, d_order_no, d_line_no, d_contractid, d_start, d_end, forcedupdate = purchases[
                        hasher]

                    if forcedupdate:
                        data['purchase_id'] = d_purchase_id
                        data.pop('order_no')
                        raise KeyError

                    # check for duplicate state
                    if d_start == start_date and d_end == end_date:
                        print '\t[!] Duplicate found. Purchase ' \
                              'for SKU "%s" with end date "%s" ' \
                              'is already uploaded' % (serial, end_date)
                except KeyError:
                    lines.append(copy.deepcopy(data))

            for line in lines:
                self.d42_rest.upload_data(line)
            data.clear()
Exemplo n.º 6
0
    def process_result(self, result, purchases):
        global full_serials
        data = {}

        if 'serial_numbers' in result:
            for device in result['serial_numbers']:
                try:
                    if self.order_no == 'common':
                        order_no = self.common
                    else:
                        order_no = self.generate_random_order_no()

                    serial = device['sr_no']

                    data.clear()

                    data.update({'order_no': order_no})
                    data.update({'completed': 'yes'})

                    data.update({'vendor': 'Cisco'})
                    data.update(
                        {'line_device_serial_nos': full_serials[serial]})
                    data.update({'line_type': 'contract'})
                    data.update({'line_item_type': 'device'})
                    data.update({'line_completed': 'yes'})

                    try:
                        line_contract_id = device['service_contract_number']
                    except KeyError:
                        line_contract_id = "Not Available"

                    data.update({'line_notes': line_contract_id})
                    data.update({'line_contract_id': line_contract_id})

                    try:
                        warranty_type = device['warranty_type']
                    except KeyError:
                        warranty_type = "Service"

                    data.update({'line_contract_type': warranty_type})

                    if warranty_type == 'Service':
                        # Skipping the services, only want the warranties
                        continue

                    try:
                        # max 64 character limit on the line service type field in Device42 (version 13.1.0)
                        service_line_description = left(
                            device['service_line_descr'], 64)
                        data.update(
                            {'line_service_type': service_line_description})
                    except KeyError:
                        pass

                    start_date = "0001-01-01"
                    end_date = device['warranty_end_date']
                    data.update({'line_end_date': end_date})

                    # Compare warranty dates by serial, contract_id, start date and end date
                    # Start date is not provided in request response so the date is simply used for hasher
                    hasher = serial + line_contract_id + start_date + end_date

                    try:
                        d_purchase_id, d_order_no, d_line_no, d_contractid, d_start, d_end, forcedupdate = \
                            purchases[hasher]

                        if forcedupdate:
                            data['purchase_id'] = d_purchase_id
                            data.pop('order_no')
                            raise KeyError

                        # check for duplicate state
                        if d_contractid == line_contract_id and d_start == start_date and d_end == end_date:
                            print '\t[!] Duplicate found. Purchase ' \
                                  'for SKU "%s" and "%s" with end date "%s" ' \
                                  'order_id: %s and line_no: %s' % (
                                      serial, line_contract_id, end_date, d_purchase_id, d_line_no)
                    except KeyError:
                        raise KeyError

                except KeyError:
                    self.d42_rest.upload_data(data)
                    data.clear()
        else:
            print 'API result did not report devices.'