Update bugzilla program to cache ip address
This commit is contained in:
parent
7c9bfbb55a
commit
9b1151290b
@ -6,25 +6,19 @@ import sqlite3
|
||||
import logging
|
||||
import os
|
||||
import xml.etree.ElementTree as ET
|
||||
import socket # Ensure you import socket for gethostbyname
|
||||
|
||||
# Common chat URL for both feeds
|
||||
# Common chat URL for the feed
|
||||
COMMON_CHAT_URL = "https://chat.koozali.org/hooks/677e97a73ddf8049989dbc8c/r9uiYpTRAXo3mkFKxHnoTwGCdtKpYaDemCpHArgz89knkwLo"
|
||||
|
||||
# Constants: Mapping Bugzilla RSS feeds to specific Rocket.Chat URLs with filtering criteria
|
||||
FEED_TO_CHAT_MAP = {
|
||||
"Bugzilla Feed 1": {
|
||||
"rss_feed": "https://bugs.koozali.org/buglist.cgi?chfield=%5BBug%20creation%5D&chfieldfrom=7d&ctype=atom&title=Bugs%20reported%20in%20the%20last%207%20days",
|
||||
"chat_url": COMMON_CHAT_URL, # Use common chat URL
|
||||
"rss_feed": None, # To be set later with the resolved IP address
|
||||
"chat_url": COMMON_CHAT_URL,
|
||||
"filter_field": "status",
|
||||
"filter_value": "open",
|
||||
"bypass_filter": True,
|
||||
},
|
||||
"Bugzilla Feed 2": {
|
||||
"rss_feed": "https://another.bugzilla.instance/buglist.cgi?chfield=%5BBug%20creation%5D&chfieldfrom=7d&ctype=atom&title=Another%20set%20of%20Bugs",
|
||||
"chat_url": COMMON_CHAT_URL, # Use common chat URL
|
||||
"filter_field": "priority",
|
||||
"filter_value": "high",
|
||||
"bypass_filter": True,
|
||||
}
|
||||
}
|
||||
|
||||
@ -54,7 +48,6 @@ def get_ip_address(domain, retries=10, delay=1):
|
||||
|
||||
raise RuntimeError(f"Unable to resolve domain '{domain}' after {retries} attempts.")
|
||||
|
||||
|
||||
# Set up logging to the current directory
|
||||
log_file = "/var/log/BugzillaToRocket.log"
|
||||
logging.basicConfig(filename=log_file, level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
||||
@ -196,9 +189,10 @@ def parse_summary(summary):
|
||||
return status, reported_by, last_changed, product, component
|
||||
|
||||
# Function to fetch and parse Bugzilla RSS feeds
|
||||
def fetch_bugzilla_feed(feed_url):
|
||||
def fetch_bugzilla_feed(feed_url, original_domain):
|
||||
headers = {'Host': original_domain} # Set Host header
|
||||
logging.info(f"Fetching feed: {feed_url}")
|
||||
feed = feedparser.parse(feed_url)
|
||||
feed = feedparser.parse(feed_url, request_headers=headers)
|
||||
entries = []
|
||||
|
||||
for entry in feed.entries:
|
||||
@ -239,13 +233,19 @@ def main():
|
||||
|
||||
setup_database()
|
||||
|
||||
# Send startup messages for each feed's chat URL
|
||||
for feed_info in FEED_TO_CHAT_MAP.values():
|
||||
send_startup_message(feed_info['chat_url'])
|
||||
# Preload IP address for Bugzilla instance
|
||||
bugzilla_ip = get_ip_address("bugs.koozali.org")
|
||||
|
||||
# Update the RSS feed URL with the resolved IP address
|
||||
FEED_TO_CHAT_MAP["Bugzilla Feed 1"]["rss_feed"] = f"http://{bugzilla_ip}/buglist.cgi?chfield=%5BBug%20creation%5D&chfieldfrom=7d&ctype=atom&title=Bugs%20reported%20in%20the%20last%207%20days"
|
||||
|
||||
# Send startup message for the feed's chat URL
|
||||
send_startup_message(FEED_TO_CHAT_MAP["Bugzilla Feed 1"]["chat_url"])
|
||||
|
||||
while True:
|
||||
for feed_name, chat_info in FEED_TO_CHAT_MAP.items():
|
||||
entries = fetch_bugzilla_feed(chat_info['rss_feed'])
|
||||
# Use the resolved IP address in fetch_bugzilla_feed
|
||||
entries = fetch_bugzilla_feed(chat_info['rss_feed'], "bugs.koozali.org")
|
||||
|
||||
filter_field = chat_info.get('filter_field', '')
|
||||
filter_value = chat_info.get('filter_value', '')
|
||||
|
Loading…
x
Reference in New Issue
Block a user