Multiple icon image plugins

You’re welcome. Here’s an example of my custom icon. It doesn’t do anything useful but at least it shows which methods need to be overwritten and how to pick data from the current check to build a URL. I’m not sure about the html.makeuri_contextless() function but for my case it works. There are some variants in the other (builtin) icons. I think you can as well build the URL string manually with the usual string formatting operations.

Furthermore, I think it is possible to hide/show an icon depending on a user’s access rights, but I didn’t do that either.

#!/usr/bin/env python
# -*- mode: Python; encoding: utf-8; indent-offset: 4; autowrap: nil -*-

# put the file here: ~/local/share/check_mk/web/plugins/icons/foo.py

from cmk.gui.plugins.views.icons.utils import (
    Icon, 
    icon_and_action_registry,
)

@icon_and_action_registry.register
class MyNewIcon(Icon):
    @classmethod
    def ident(cls):
        return 'my_new_icon'

    def render(self, what, row, tags, custom_vars):
        if (what == 'service' and row['service_check_command'] == 'check_mk-df'):
            if row['service_description'] == 'Filesystem /':
                host = row["host_name"]
                urlvars = [
                    ("host", host),
                    ("site", row['site']),
                    ("view_name", "host"),
                ]
                url = html.makeuri_contextless(urlvars, filename="view.py")
                # gives: http://.../SITE/check_mk/view.py?host=...&site=...&view_name=host

                # "forth" refers to an icon below ~share/check_mk/web/htdocs/themes/*/images/
                return 'forth', _('Jump to %s' % host), url

    # True: display icon in column, False: display it in the action menu
    def default_toplevel(self):
        return True

Have fun :partying_face:

1 Like