<commit_before><?php

require_once dirname(__FILE__) . "/../database.php";


class WeatherMapDataSource_cactihost extends WeatherMapDataSource
{
    public function __construct()
    {
        parent::__construct();

        $this->regexpsHandled = array(
            '/^cactihost:(\d+)$/'
        );

        $this->name= "CactiHost";

    }

    function Init(&$map)
    {
        if ($map->context == 'cacti') {
            if (function_exists('db_fetch_row')) {
                return true;
            } else {
                wm_debug('ReadData CactiHost: Cacti database library not found.\n');
            }
        } else {
            wm_debug("ReadData CactiHost: Can only run from Cacti environment.\n");
        }

        return false;
    }

    /**
     * @param string $targetstring
     * @param WeatherMap $map
     * @param WeatherMapDataItem $item
     * @return array
     */
    function ReadData($targetstring, &$map, &$item)
    {
        if (preg_match($this->regexpsHandled[0], $targetstring, $matches)) {
            $cacti_id = intval($matches[1]);

            $pdo = weathermap_get_pdo();

            $statement=$pdo->prepare("\"select * from host where id=?");

            // 0=disabled
            // 1=down
            // 2=recovering
            // 3=up

            $statement->execute(array($cacti_id));

            $state = -1;
            $result = $statement->fetch(PDO::FETCH_ASSOC);
            if (isset($result)) {
                // create a note, which can be used in icon filenames or labels more nicely
                if ($result['status'] == 1) {
                    $state = 1;
                    $statename = 'down';
                }
                if ($result['status'] == 2) {
                    $state = 2;
                    $statename = 'recovering';
                }
                if ($result['status'] == 3) {
                    $state = 3;
                    $statename = 'up';
                }
                if ($result['disabled']) {
                    $state = 0;
                    $statename = 'disabled';
                }

                $this->data[IN] = $state;
                $this->data[OUT] = $state;
                $item->add_note("state", $statename);
                $item->add_note("cacti_description", $result['description']);

                $item->add_note("cacti_hostname", $result['hostname']);
                $item->add_note("cacti_curtime", $result['cur_time']);
                $item->add_note("cacti_avgtime", $result['avg_time']);
                $item->add_note("cacti_mintime", $result['min_time']);
                $item->add_note("cacti_maxtime", $result['max_time']);
                $item->add_note("cacti_availability", $result['availability']);

                $item->add_note("cacti_faildate", $result['status_fail_date']);
                $item->add_note("cacti_recdate", $result['status_rec_date']);
            }
        }
        return $this->ReturnData();
    }
}


// vim:ts=4:sw=4:
<commit_msg>Fixed (another :-( )typo in cactihost<commit_after><?php

require_once dirname(__FILE__) . "/../database.php";


class WeatherMapDataSource_cactihost extends WeatherMapDataSource
{
    public function __construct()
    {
        parent::__construct();

        $this->regexpsHandled = array(
            '/^cactihost:(\d+)$/'
        );

        $this->name= "CactiHost";

    }

    function Init(&$map)
    {
        if ($map->context == 'cacti') {
            if (function_exists('db_fetch_row')) {
                return true;
            } else {
                wm_debug('ReadData CactiHost: Cacti database library not found.\n');
            }
        } else {
            wm_debug("ReadData CactiHost: Can only run from Cacti environment.\n");
        }

        return false;
    }

    /**
     * @param string $targetstring
     * @param WeatherMap $map
     * @param WeatherMapDataItem $item
     * @return array
     */
    function ReadData($targetstring, &$map, &$item)
    {
        if (preg_match($this->regexpsHandled[0], $targetstring, $matches)) {
            $cacti_id = intval($matches[1]);

            $pdo = weathermap_get_pdo();

            $statement=$pdo->prepare("select * from host where id=?");

            // 0=disabled
            // 1=down
            // 2=recovering
            // 3=up

            $statement->execute(array($cacti_id));

            $state = -1;
            $result = $statement->fetch(PDO::FETCH_ASSOC);
            if (isset($result)) {
                // create a note, which can be used in icon filenames or labels more nicely
                if ($result['status'] == 1) {
                    $state = 1;
                    $statename = 'down';
                }
                if ($result['status'] == 2) {
                    $state = 2;
                    $statename = 'recovering';
                }
                if ($result['status'] == 3) {
                    $state = 3;
                    $statename = 'up';
                }
                if ($result['disabled']) {
                    $state = 0;
                    $statename = 'disabled';
                }

                $this->data[IN] = $state;
                $this->data[OUT] = $state;
                $item->add_note("state", $statename);
                $item->add_note("cacti_description", $result['description']);

                $item->add_note("cacti_hostname", $result['hostname']);
                $item->add_note("cacti_curtime", $result['cur_time']);
                $item->add_note("cacti_avgtime", $result['avg_time']);
                $item->add_note("cacti_mintime", $result['min_time']);
                $item->add_note("cacti_maxtime", $result['max_time']);
                $item->add_note("cacti_availability", $result['availability']);

                $item->add_note("cacti_faildate", $result['status_fail_date']);
                $item->add_note("cacti_recdate", $result['status_rec_date']);
            }
        }
        return $this->ReturnData();
    }
}


// vim:ts=4:sw=4:

{'fraction_non_alphanumeric': 0.14995051138238205, 'fraction_numerical': 0.005278785879247773, 'mean_word_length': 1.591025641025641, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5994588', 'n_tokens_mistral': 1867, 'n_tokens_neox': 1731, 'n_words': 308}