Multiple icon image plugins

I have previously been working on some icon plugins, where i rendered multiple icons to do some custom actions against a ticket system. But after i upgraded CMK(fairly big version upgrade), it seems that you can only add 1 icon.
As far as i can see in the cmk source, you can only add 1 dict to multisite_icons_and_actions[‘icon_image’] = {'paint: icon1()}
where in previous version you did multisite_icons.append({‘paint’: icon1()}, {‘paint’: icon2()}) and this is even still documented in the script but does not work as far as i can see.

Does any one know if it’s possible to have multiple icon image plugins, without having to hack it a bit? (i have done this but it’s kinda ugly)

I was under the impression that multisite_icons_and_actions is deprecated and we should write a subclass of Icon instead (like those in lib/python/cmk/gui/plugins/views/icons/ For multiple icons probably multiple such classes are required. I wrote such a subclass and placed it in ~/local/share/check_mk/web/plugins/icons/ It’s just one icon, though. But when I “duplicate” my class and rename it slightly, then two icons are shown.

I can see that there’s some stuff i need to catch up on! Thank you :slight_smile:

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/

from cmk.gui.plugins.views.icons.utils import (

class MyNewIcon(Icon):
    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="")
                # gives: http://.../SITE/check_mk/

                # "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