Tools for printer discovery and monitoring: - snmp_scanner.py: SNMP-based printer discovery - generate_printer_templates.py: Generate Zabbix templates - analyze_supplies.py: Analyze printer supply levels - extract_summary.py: Extract printer data summaries Includes Zabbix templates for: - HP Color/Mono printers - HP DesignJet T1700 - Xerox Color/Mono/Enterprise printers 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
283 lines
9.8 KiB
Python
283 lines
9.8 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Regenerate HP DesignJet T1700 Zabbix template with proper UUIDs
|
|
Fixes "UUIDv4 is expected" import error
|
|
"""
|
|
|
|
import uuid
|
|
import yaml
|
|
|
|
def generate_uuid():
|
|
"""Generate UUID without hyphens (Zabbix format)"""
|
|
return uuid.uuid4().hex
|
|
|
|
# HP DesignJet T1700 Template with proper UUID generation
|
|
template = {
|
|
'zabbix_export': {
|
|
'version': '7.4',
|
|
'template_groups': [
|
|
{
|
|
'uuid': '3cd4e8d0b828464e8f4b3becf13a9dbd', # Standard Printers group UUID
|
|
'name': 'Printers'
|
|
}
|
|
],
|
|
'templates': [
|
|
{
|
|
'uuid': generate_uuid(),
|
|
'template': 'HP DesignJet T1700',
|
|
'name': 'HP DesignJet T1700',
|
|
'description': '''HP DesignJet T1700/T1700dr PostScript Large Format Printer (44" wide) with 6-color ink system.
|
|
Uses HP-specific OIDs for ink levels (1.3.6.1.4.1.11.2.3.9.4.2.1.4.1.5.4.X.1.0)
|
|
|
|
Correct HP 730 300ml cartridge mapping (verified from actual installation):
|
|
- P2V68A = Cyan
|
|
- P2V69A = Magenta
|
|
- P2V70A = Yellow
|
|
- P2V71A = Matte Black
|
|
- P2V72A = Gray
|
|
- P2V73A = Photo Black''',
|
|
'groups': [
|
|
{'name': 'Printers'}
|
|
],
|
|
'items': []
|
|
}
|
|
]
|
|
}
|
|
}
|
|
|
|
# Ink cartridge definitions with correct SNMP index mapping
|
|
INK_CARTRIDGES = [
|
|
{
|
|
'color': 'Matte Black',
|
|
'key': 'matte_black',
|
|
'part_oid': '1.3.6.1.2.1.43.11.1.1.6.1.3', # Index 3
|
|
'level_oid': '1.3.6.1.4.1.11.2.3.9.4.2.1.4.1.5.4.3.1.0',
|
|
'part_number': 'P2V71A',
|
|
'description': 'Matte Black Ink'
|
|
},
|
|
{
|
|
'color': 'Photo Black',
|
|
'key': 'photo_black',
|
|
'part_oid': '1.3.6.1.2.1.43.11.1.1.6.1.2', # Index 2
|
|
'level_oid': '1.3.6.1.4.1.11.2.3.9.4.2.1.4.1.5.4.2.1.0',
|
|
'part_number': 'P2V73A',
|
|
'description': 'Photo Black Ink'
|
|
},
|
|
{
|
|
'color': 'Cyan',
|
|
'key': 'cyan',
|
|
'part_oid': '1.3.6.1.2.1.43.11.1.1.6.1.6', # Index 6
|
|
'level_oid': '1.3.6.1.4.1.11.2.3.9.4.2.1.4.1.5.4.6.1.0',
|
|
'part_number': 'P2V68A',
|
|
'description': 'Cyan Ink'
|
|
},
|
|
{
|
|
'color': 'Magenta',
|
|
'key': 'magenta',
|
|
'part_oid': '1.3.6.1.2.1.43.11.1.1.6.1.5', # Index 5
|
|
'level_oid': '1.3.6.1.4.1.11.2.3.9.4.2.1.4.1.5.4.5.1.0',
|
|
'part_number': 'P2V69A',
|
|
'description': 'Magenta Ink'
|
|
},
|
|
{
|
|
'color': 'Yellow',
|
|
'key': 'yellow',
|
|
'part_oid': '1.3.6.1.2.1.43.11.1.1.6.1.4', # Index 4
|
|
'level_oid': '1.3.6.1.4.1.11.2.3.9.4.2.1.4.1.5.4.4.1.0',
|
|
'part_number': 'P2V70A',
|
|
'description': 'Yellow Ink'
|
|
},
|
|
{
|
|
'color': 'Gray',
|
|
'key': 'gray',
|
|
'part_oid': '1.3.6.1.2.1.43.11.1.1.6.1.1', # Index 1
|
|
'level_oid': '1.3.6.1.4.1.11.2.3.9.4.2.1.4.1.5.4.1.1.0',
|
|
'part_number': 'P2V72A',
|
|
'description': 'Gray Ink'
|
|
}
|
|
]
|
|
|
|
# Standard preprocessing for text fields (handles hex-encoded and binary SNMP data)
|
|
TEXT_PREPROCESSING = [
|
|
{
|
|
'type': 'JAVASCRIPT',
|
|
'parameters': [
|
|
"// Handle hex-encoded SNMP strings\n// Try multiple approaches to convert hex to ASCII\n\n// First, check if it looks like hex (with spaces, newlines, or other separators)\nvar hexPattern = /^[0-9A-Fa-f\\s]+$/;\nif (hexPattern.test(value) && value.length > 4) {\n // Extract all hex pairs (2 characters)\n var hexBytes = value.match(/[0-9A-Fa-f]{2}/g);\n if (hexBytes && hexBytes.length > 0) {\n var result = '';\n for (var i = 0; i < hexBytes.length; i++) {\n var code = parseInt(hexBytes[i], 16);\n // Only keep printable ASCII (0x20-0x7E)\n if (code >= 32 && code <= 126) {\n result += String.fromCharCode(code);\n }\n }\n if (result.length > 0) {\n return result;\n }\n }\n}\n\n// Fallback: Remove non-printable characters\nreturn value.replace(/[^\\x20-\\x7E]/g, '');"
|
|
]
|
|
}
|
|
]
|
|
|
|
# Printer info items
|
|
items = template['zabbix_export']['templates'][0]['items']
|
|
|
|
# Add basic printer info items
|
|
items.extend([
|
|
{
|
|
'uuid': generate_uuid(),
|
|
'name': 'Printer Model',
|
|
'type': 'SNMP_AGENT',
|
|
'snmp_oid': '1.3.6.1.2.1.25.3.2.1.3.1',
|
|
'key': 'printer.model',
|
|
'delay': '1h',
|
|
'history': '90d',
|
|
'trends': '0d',
|
|
'value_type': 'TEXT',
|
|
'description': 'Printer Model',
|
|
'preprocessing': TEXT_PREPROCESSING,
|
|
'tags': [
|
|
{'tag': 'component', 'value': 'printer'},
|
|
{'tag': 'type', 'value': 'info'}
|
|
]
|
|
},
|
|
{
|
|
'uuid': generate_uuid(),
|
|
'name': 'Printer Hostname',
|
|
'type': 'SNMP_AGENT',
|
|
'snmp_oid': '1.3.6.1.2.1.1.5.0',
|
|
'key': 'printer.hostname',
|
|
'delay': '1h',
|
|
'history': '90d',
|
|
'trends': '0d',
|
|
'value_type': 'TEXT',
|
|
'description': 'Printer Hostname',
|
|
'preprocessing': TEXT_PREPROCESSING,
|
|
'tags': [
|
|
{'tag': 'component', 'value': 'printer'},
|
|
{'tag': 'type', 'value': 'info'}
|
|
]
|
|
},
|
|
{
|
|
'uuid': generate_uuid(),
|
|
'name': 'Printer Serial Number',
|
|
'type': 'SNMP_AGENT',
|
|
'snmp_oid': '1.3.6.1.4.1.11.2.3.9.4.2.1.1.3.3.0',
|
|
'key': 'printer.serial',
|
|
'delay': '1h',
|
|
'history': '90d',
|
|
'trends': '0d',
|
|
'value_type': 'TEXT',
|
|
'description': 'Printer Serial Number (HP-specific OID)',
|
|
'preprocessing': TEXT_PREPROCESSING,
|
|
'tags': [
|
|
{'tag': 'component', 'value': 'printer'},
|
|
{'tag': 'type', 'value': 'info'}
|
|
]
|
|
},
|
|
{
|
|
'uuid': generate_uuid(),
|
|
'name': 'System Location',
|
|
'type': 'SNMP_AGENT',
|
|
'snmp_oid': '1.3.6.1.2.1.1.6.0',
|
|
'key': 'printer.location',
|
|
'delay': '1h',
|
|
'history': '90d',
|
|
'trends': '0d',
|
|
'value_type': 'TEXT',
|
|
'description': 'System Location',
|
|
'preprocessing': TEXT_PREPROCESSING,
|
|
'tags': [
|
|
{'tag': 'component', 'value': 'printer'},
|
|
{'tag': 'type', 'value': 'info'}
|
|
]
|
|
},
|
|
{
|
|
'uuid': generate_uuid(),
|
|
'name': 'Firmware Version',
|
|
'type': 'SNMP_AGENT',
|
|
'snmp_oid': '1.3.6.1.4.1.11.2.3.9.4.2.1.1.3.6.0',
|
|
'key': 'printer.firmware',
|
|
'delay': '1h',
|
|
'history': '90d',
|
|
'trends': '0d',
|
|
'value_type': 'TEXT',
|
|
'description': 'Printer Firmware Version',
|
|
'preprocessing': TEXT_PREPROCESSING,
|
|
'tags': [
|
|
{'tag': 'component', 'value': 'printer'},
|
|
{'tag': 'type', 'value': 'info'}
|
|
]
|
|
}
|
|
])
|
|
|
|
# Add ink cartridge items
|
|
for ink in INK_CARTRIDGES:
|
|
# Part number item
|
|
items.append({
|
|
'uuid': generate_uuid(),
|
|
'name': f"{ink['color']} Cartridge Part Number",
|
|
'type': 'SNMP_AGENT',
|
|
'snmp_oid': ink['part_oid'],
|
|
'key': f"printer.cartridge.{ink['key']}",
|
|
'delay': '1h',
|
|
'history': '90d',
|
|
'trends': '0d',
|
|
'value_type': 'TEXT',
|
|
'description': f"{ink['description']} Cartridge Part Number (HP 730 {ink['part_number']})",
|
|
'preprocessing': TEXT_PREPROCESSING,
|
|
'tags': [
|
|
{'tag': 'component', 'value': 'supplies'},
|
|
{'tag': 'type', 'value': 'info'}
|
|
]
|
|
})
|
|
|
|
# Ink level item with triggers
|
|
items.append({
|
|
'uuid': generate_uuid(),
|
|
'name': f"{ink['color']} Ink Level",
|
|
'type': 'SNMP_AGENT',
|
|
'snmp_oid': ink['level_oid'],
|
|
'key': f"printer.ink.{ink['key']}",
|
|
'delay': '1h',
|
|
'history': '90d',
|
|
'trends': '365d',
|
|
'value_type': 'FLOAT',
|
|
'units': '%',
|
|
'description': f"{ink['description']} Level Percentage (HP proprietary OID)",
|
|
'tags': [
|
|
{'tag': 'component', 'value': 'supplies'},
|
|
{'tag': 'type', 'value': 'level'},
|
|
{'tag': 'color', 'value': ink['key']}
|
|
],
|
|
'triggers': [
|
|
{
|
|
'uuid': generate_uuid(),
|
|
'expression': f"last(/HP DesignJet T1700/printer.ink.{ink['key']})<20 and length(last(/HP DesignJet T1700/printer.cartridge.{ink['key']}))>0",
|
|
'name': f"{ink['color']} Ink Level is low on {{{{HOST.NAME}}}}. Current level: {{{{ITEM.LASTVALUE}}}}%. Replacement part: {{{{ITEM.LASTVALUE2}}}}",
|
|
'priority': 'WARNING',
|
|
'tags': [
|
|
{'tag': 'scope', 'value': 'availability'}
|
|
]
|
|
},
|
|
{
|
|
'uuid': generate_uuid(),
|
|
'expression': f"last(/HP DesignJet T1700/printer.ink.{ink['key']})<10 and length(last(/HP DesignJet T1700/printer.cartridge.{ink['key']}))>0",
|
|
'name': f"{ink['color']} Ink Level is critically low on {{{{HOST.NAME}}}}. Current level: {{{{ITEM.LASTVALUE}}}}%. Replacement part: {{{{ITEM.LASTVALUE2}}}}",
|
|
'priority': 'HIGH',
|
|
'tags': [
|
|
{'tag': 'scope', 'value': 'availability'}
|
|
]
|
|
}
|
|
]
|
|
})
|
|
|
|
# Generate YAML output
|
|
yaml_output = yaml.dump(template, default_flow_style=False, sort_keys=False, allow_unicode=True, width=1000)
|
|
|
|
# Save to file
|
|
with open('zabbix_template_hp_designjet_t1700.yaml', 'w') as f:
|
|
f.write(yaml_output)
|
|
|
|
print("=" * 80)
|
|
print("HP DesignJet T1700 Zabbix Template Generated")
|
|
print("=" * 80)
|
|
print(f"\n✓ Template saved to: zabbix_template_hp_designjet_t1700.yaml")
|
|
print(f"✓ All UUIDs generated properly (32-char hex format)")
|
|
print(f"✓ Template includes {len(INK_CARTRIDGES)} ink cartridges with correct OID mapping")
|
|
print(f"✓ Ready for import into Zabbix 7.4")
|
|
print("\nImport Instructions:")
|
|
print("1. Go to Zabbix: Data collection → Templates")
|
|
print("2. Click 'Import'")
|
|
print("3. Select zabbix_template_hp_designjet_t1700.yaml")
|
|
print("4. Click 'Import'")
|
|
print("\n" + "=" * 80)
|