summaryrefslogtreecommitdiffstats
path: root/library/Icinga/Application/Hook/GrapherHook.php
blob: dfb2135612cdeb0a935d96da712f06efb73fe9bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
/* Icinga Web 2 | (c) 2013 Icinga Development Team | GPLv2+ */

namespace Icinga\Application\Hook;

use Icinga\Exception\ProgrammingError;
use Icinga\Module\Monitoring\Object\MonitoredObject;

/**
 * Icinga Web Grapher Hook base class
 *
 * Extend this class if you want to integrate your graphing solution nicely into
 * Icinga Web.
 */
abstract class GrapherHook extends WebBaseHook
{
    /**
     * Whether this grapher provides previews
     *
     * @var bool
     */
    protected $hasPreviews = false;

    /**
     * Whether this grapher provides tiny previews
     *
     * @var bool
     */
    protected $hasTinyPreviews = false;

    /**
     * Constructor must live without arguments right now
     *
     * Therefore the constructor is final, we might change our opinion about
     * this one far day
     */
    final public function __construct()
    {
        $this->init();
    }

    /**
     * Overwrite this function if you want to do some initialization stuff
     *
     * @return void
     */
    protected function init()
    {
    }

    /**
     * Whether this grapher provides previews
     *
     * @return bool
     */
    public function hasPreviews()
    {
        return $this->hasPreviews;
    }

    /**
     * Whether this grapher provides tiny previews
     *
     * @return bool
     */
    public function hasTinyPreviews()
    {
        return $this->hasTinyPreviews;
    }

    /**
     * Whether a graph for the monitoring object exist
     *
     * @param   MonitoredObject $object
     *
     * @return  bool
     */
    abstract public function has(MonitoredObject $object);

    /**
     * Get a preview for the given object
     *
     * This function must return an empty string if no graph exists.
     *
     * @param   MonitoredObject $object
     *
     * @return  string
     * @throws  ProgrammingError
     *
     */
    public function getPreviewHtml(MonitoredObject $object)
    {
        throw new ProgrammingError('This hook provide previews but it is not implemented');
    }


    /**
     * Get a tiny preview for the given object
     *
     * This function must return an empty string if no graph exists.
     *
     * @param   MonitoredObject $object
     *
     * @return  string
     * @throws  ProgrammingError
     */
    public function getTinyPreviewHtml(MonitoredObject $object)
    {
        throw new ProgrammingError('This hook provide tiny previews but it is not implemented');
    }
}