from odoo import models, api
from odoo.http import Controller, route, request
import base64

class NodeMetricsReportController(Controller):

    @route(['/node_metrics/report/<int:index_id>'], type='http', auth='user')
    def report(self, index_id):
        index_record = request.env['hg.index'].sudo().browse(index_id)
        if not index_record.exists():
            return "Record not found"
        image_data = index_record.generate_graph_image()
        img_html = f'<img src="data:image/png;base64,{image_data}" alt="Node Metrics Graph"/>'
        return img_html