0
我使用Nagios的開發的插件,但在特定的主機上運行時,我得到一個錯誤。我通常會進行調試,但是對於python編程來說是非常新的。我得到的錯誤是:類型錯誤:字符串索引必須是整數 - check_dell_warrant.py
Traceback (most recent call last):
File "/usr/lib64/nagios/plugins/check_dell_warranty.py", line 755, in <module>
parse_exit(RESULT, options.short_output)
File "/usr/lib64/nagios/plugins/check_dell_warranty.py", line 589, in parse_exit
days, short_output)
File "/usr/lib64/nagios/plugins/check_dell_warranty.py", line 557, in process_asset
days, short_output)
File "/usr/lib64/nagios/plugins/check_dell_warranty.py", line 497, in build_warranty_line
description = warranty['ServiceLevelDescription']
TypeError: string indices must be integers
該腳本的代碼所示:
def build_warranty_line(warranty, full_line, days, short_output):
'''
This function takes a warranty object and parses the salient information
out. It then calculates the number of days remaining in the warranty
period, and builds a line for Nagios outputting.
'''
description = warranty['ServiceLevelDescription']
end_date = warranty['EndDate']
start_date = warranty['StartDate']
provider = warranty['ServiceProvider']
logger.debug('Found: Start date: {0}, End Date: {1},Description: {2}, '
'Provider: {3}'.format(start_date, end_date, description,
provider))
如果我在調試模式下運行腳本它表明這是傳遞給這個函數的原始數據是:
DEBUG - Attempting to load libsmbios_c.
DEBUG - Unable to load libsmbios_c continuing.
DEBUG - Obtaining serial number via OpenManage.
DEBUG - Requesting service tags: GSF0YX1
DEBUG - Requesting warranty information from Dell url:
https://api.dell.com/support/v2/assetinfo/warranty/tags.json?
apikey=1adecee8a60444738f280aad1cd87d0e&svctags=GSF0YX1
DEBUG - Raw output received:
{u'GetAssetWarrantyResponse': {u'@xmlns': u'http://tempuri.org/', u'GetAssetWarrantyResult': {u'Faults': None, u'@a': u'http://schemas.datacontract.org/2004/07/Dell.AWR.Domain.Asset', u'@i': u'http://www.w3.org/2001/XMLSchema-instance', u'Response': {u'DellAsset': {u'MachineDescription': u'PowerEdge R720', u'ShipDate': u'2013-05-08T00:00:00', u'ServiceTag': u'GSF0YX1', u'OrderNumber': 68701126, u'LocalChannel': u'IRL', u'AssetParts': {u'@nil': u'true'}, u'CountryLookupCode': 808, u'ItemClassCode': u'TE002', u'IsDuplicate': u'false', u'ParentServiceTag': {u'@nil': u'true'}, u'CustomerNumber': 5503647, u'Warranties': {u'Warranty': {u'StartDate': u'2013-05-08T00:00:00', u'EndDate': u'2016-05- 08T23:59:59', u'ServiceProvider': {u'@nil': u'true'}, u'ServiceLevelCode': u'ND', u'ItemNumber': u'709-11115', u'EntitlementType': u'INITIAL', u'ServiceLevelDescription': u'Next Business Day', u'ServiceLevelGroup': 99999}}}}}}}
DEBUG - Testing for faults in json response.
DEBUG - Raw fault return: None
DEBUG - No faults found.
DEBUG - Beginning to parse results and construct exit line and code.
DEBUG - Assets obtained: {u'MachineDescription': u'PowerEdge R720', u'ShipDate': u'2013-05-08T00:00:00', u'ServiceTag': u'GSF0YX1', u'OrderNumber': 68701126, u'LocalChannel': u'IRL', u'AssetParts': {u'@nil': u'true'}, u'CountryLookupCode': 808, u'ItemClassCode': u'TE002', u'IsDuplicate': u'false', u'ParentServiceTag': {u'@nil': u'true'}, u'CustomerNumber': 5503647, u'Warranties': {u'Warranty': {u'StartDate': u'2013-05-08T00:00:00', u'EndDate': u'2016-05-08T23:59:59', u'ServiceProvider': {u'@nil': u'true'}, u'ServiceLevelCode': u'ND', u'ItemNumber': u'709-11115', u'EntitlementType': u'INITIAL', u'ServiceLevelDescription': u'Next Business Day', u'ServiceLevelGroup': 99999}}}
DEBUG - A single asset is being processed.
DEBUG - Raw asset being processed: {u'MachineDescription': u'PowerEdge R720', u'ShipDate': u'2013-05-08T00:00:00', u'ServiceTag': u'GSF0YX1', u'OrderNumber': 68701126, u'LocalChannel': u'IRL', u'AssetParts': {u'@nil': u'true'}, u'CountryLookupCode': 808, u'ItemClassCode': u'TE002', u'IsDuplicate': u'false', u'ParentServiceTag': {u'@nil': u'true'}, u'CustomerNumber': 5503647, u'Warranties': {u'Warranty': {u'StartDate': u'2013-05-08T00:00:00', u'EndDate': u'2016-05-08T23:59:59', u'ServiceProvider': {u'@nil': u'true'}, u'ServiceLevelCode': u'ND', u'ItemNumber': u'709-11115', u'EntitlementType': u'INITIAL', u'ServiceLevelDescription': u'Next Business Day', u'ServiceLevelGroup': 99999}}}
有人可以幫我解決這個問題嗎?
我實際上並沒有自己編寫腳本,但我使用的版本在這裏:[link](https://gitorious.org/smarmy/check_dell_warranty/source/b6438fbef45ba22be3bf0aa2e0aa2e444a384813:check_dell_warranty.py) – user3216306