<commit_before>################################################################################
# Copyright 2005-2014 MERETHIS
# Centreon is developped by : <NAME> and <NAME> under
# GPL Licence 2.0.
# 
# This program is free software; you can redistribute it and/or modify it under 
# the terms of the GNU General Public License as published by the Free Software 
# Foundation ; either version 2 of the License.
# 
# This program is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
# PARTICULAR PURPOSE. See the GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License along with 
# this program; if not, see <http://www.gnu.org/licenses>.
# 
# Linking this program statically or dynamically with other modules is making a 
# combined work based on this program. Thus, the terms and conditions of the GNU 
# General Public License cover the whole combination.
# 
# As a special exception, the copyright holders of this program give MERETHIS 
# permission to link this program with independent modules to produce an executable, 
# regardless of the license terms of these independent modules, and to copy and 
# distribute the resulting executable under terms of MERETHIS choice, provided that 
# MERETHIS also meet, for each linked independent module, the terms  and conditions 
# of the license of that module. An independent module is a module which is not 
# derived from this program. If you modify this program, you may extend this 
# exception to your version of the program, but you are not obliged to do so. If you
# do not wish to do so, delete this exception statement from your version.
# 
# For more information : <EMAIL>
# Authors : <NAME> <<EMAIL>>
#
####################################################################################

package apps::pacemaker::local::mode::crm;

use base qw(centreon::plugins::mode);

use strict;
use warnings;

sub new {
    my ($class, %options) = @_;
    my $self = $class->SUPER::new(package => __PACKAGE__, %options);
    bless $self, $class;
    
    $self->{version} = '1.0';
    $options{options}->add_options(arguments =>
                                { 
                                  "hostname:s"        => { name => 'hostname' },
                                  "remote"            => { name => 'remote' },
                                  "ssh-option:s@"     => { name => 'ssh_option' },
                                  "ssh-path:s"        => { name => 'ssh_path' },
                                  "ssh-command:s"     => { name => 'ssh_command', default => 'ssh' },
                                  "timeout:s"         => { name => 'timeout', default => 30 },
                                  "sudo"              => { name => 'sudo' },
                                  "command:s"         => { name => 'command', default => 'crm_mon' },
                                  "command-path:s"    => { name => 'command_path', default => '/usr/sbin' },
                                  "command-options:s"           => { name => 'command_options', default => '-1 -r -f 2>&1' },
                                  "warning"                     => { name => 'warning', },
                                  "standbyignore"               => { name => 'standbyignore', },
                                  "resources:s"                 => { name => 'resources', },
                                  "ignore-failed-actions:s@"    => { name => 'ignore_failed_actions', },
                                });
    $self->{threshold} = 'CRITICAL';
    $self->{resources_check} = {};
    return $self;
}

sub check_options {
    my ($self, %options) = @_;
    $self->SUPER::init(%options);

    if (defined($self->{option_results}->{warning})) {
        $self->{threshold} = 'WARNING';
    }
    if (defined($self->{option_results}->{resources})) {
        foreach (split(/,/, $self->{option_results}->{resources})) {
            my ($rsc_name, $node) = split(/:/, $_);
            if (defined($rsc_name) && $rsc_name ne '' && 
                defined($node) && $node ne '') {
                $self->{resources_check}->{$rsc_name} = $node;
            }
        }
    }
}

sub parse_output {
    my ($self, %options) = @_;
    
    my @standby;
    $self->{output}->output_add(severity => 'OK', 
                                short_msg => "Cluster is OK");
    foreach my $line (split /\n/, $options{crm_out}) {
        if ($line =~ /Connection to cluster failed\:(.*)/i ) {
            $self->{output}->output_add(severity => 'CRITICAL', 
                                        short_msg => "Connection to cluster FAILED: $1");
            return ;
        } elsif ($line =~ /Current DC:/) {
            if ($line !~ m/partition with quorum$/ ) {
                $self->{output}->output_add(severity => 'CRITICAL', 
                                            short_msg => "No Quorum");
            }
        } elsif ($line =~ /^offline:\s*\[\s*(\S.*?)\s*\]/i) {
            # Count offline nodes
            my @offline = split( /\s+/, $1 );
            my $numoffline = scalar @offline;
            $self->{output}->output_add(severity => $self->{threshold}, 
                                        short_msg => "$numoffline Nodes Offline");
        } elsif ($line =~ /^node\s+(\S.*):\s*standby/i) {
            push @standby, $1;
        } elsif ($line =~ /\s*([0-9a-zA-Z_\-]+)\s+\(\S+\)\:\s+Started\s+([0-9a-zA-Z_\-]+)/) {
            # Check Resources pos
            if (defined($self->{resources_check}->{$1}) && $self->{resources_check}->{$1} ne $2) {
                $self->{output}->output_add(severity => $self->{threshold}, 
                                            short_msg => "Resource '$1' is on node '$2'");
            }
        } elsif ($line =~ /\s*([0-9a-zA-Z_\-]+)\s+\(\S+\)\:\s+Stopped/) {
            $self->{output}->output_add(severity => $self->{threshold}, 
                                        short_msg => "Resource '$1' Stopped");
        } elsif ($line =~ m/\s*stopped\:\s*\[(.*)\]/i) {
            # Check Master/Slave stopped
            $self->{output}->output_add(severity => $self->{threshold}, 
                                        short_msg => "$1 Stopped");
        } elsif ($line =~ /^Failed actions\:/) {
            # Check Failed Actions
            my $skip = 0;
            foreach ($self->{option_results}->{ignore_failed_actions}) {
                if ($line =~ /$_/) {
                    $skip = 1;
                    last;<commit_msg>Fix pacemaker<commit_after>################################################################################
# Copyright 2005-2014 MERETHIS
# Centreon is developped by : <NAME> and <NAME> under
# GPL Licence 2.0.
# 
# This program is free software; you can redistribute it and/or modify it under 
# the terms of the GNU General Public License as published by the Free Software 
# Foundation ; either version 2 of the License.
# 
# This program is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
# PARTICULAR PURPOSE. See the GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License along with 
# this program; if not, see <http://www.gnu.org/licenses>.
# 
# Linking this program statically or dynamically with other modules is making a 
# combined work based on this program. Thus, the terms and conditions of the GNU 
# General Public License cover the whole combination.
# 
# As a special exception, the copyright holders of this program give MERETHIS 
# permission to link this program with independent modules to produce an executable, 
# regardless of the license terms of these independent modules, and to copy and 
# distribute the resulting executable under terms of MERETHIS choice, provided that 
# MERETHIS also meet, for each linked independent module, the terms  and conditions 
# of the license of that module. An independent module is a module which is not 
# derived from this program. If you modify this program, you may extend this 
# exception to your version of the program, but you are not obliged to do so. If you
# do not wish to do so, delete this exception statement from your version.
# 
# For more information : <EMAIL>
# Authors : <NAME> <<EMAIL>>
#
####################################################################################

package apps::pacemaker::local::mode::crm;

use base qw(centreon::plugins::mode);

use strict;
use warnings;

sub new {
    my ($class, %options) = @_;
    my $self = $class->SUPER::new(package => __PACKAGE__, %options);
    bless $self, $class;
    
    $self->{version} = '1.0';
    $options{options}->add_options(arguments =>
                                { 
                                  "hostname:s"        => { name => 'hostname' },
                                  "remote"            => { name => 'remote' },
                                  "ssh-option:s@"     => { name => 'ssh_option' },
                                  "ssh-path:s"        => { name => 'ssh_path' },
                                  "ssh-command:s"     => { name => 'ssh_command', default => 'ssh' },
                                  "timeout:s"         => { name => 'timeout', default => 30 },
                                  "sudo"              => { name => 'sudo' },
                                  "command:s"         => { name => 'command', default => 'crm_mon' },
                                  "command-path:s"    => { name => 'command_path', default => '/usr/sbin' },
                                  "command-options:s"           => { name => 'command_options', default => '-1 -r -f 2>&1' },
                                  "warning"                     => { name => 'warning', },
                                  "standbyignore"               => { name => 'standbyignore', },
                                  "resources:s"                 => { name => 'resources', },
                                  "ignore-failed-actions:s@"    => { name => 'ignore_failed_actions', },
                                });
    $self->{threshold} = 'CRITICAL';
    $self->{resources_check} = {};
    return $self;
}

sub check_options {
    my ($self, %options) = @_;
    $self->SUPER::init(%options);

    if (defined($self->{option_results}->{warning})) {
        $self->{threshold} = 'WARNING';
    }
    if (defined($self->{option_results}->{resources})) {
        foreach (split(/,/, $self->{option_results}->{resources})) {
            my ($rsc_name, $node) = split(/:/, $_);
            if (defined($rsc_name) && $rsc_name ne '' && 
                defined($node) && $node ne '') {
                $self->{resources_check}->{$rsc_name} = $node;
            }
        }
    }
}

sub parse_output {
    my ($self, %options) = @_;
    
    my @standby;
    $self->{output}->output_add(severity => 'OK', 
                                short_msg => "Cluster is OK");
    foreach my $line (split /\n/, $options{crm_out}) {
        if ($line =~ /Connection to cluster failed\:(.*)/i ) {
            $self->{output}->output_add(severity => 'CRITICAL', 
                                        short_msg => "Connection to cluster FAILED: $1");
            return ;
        } elsif ($line =~ /Current DC:/) {
            if ($line !~ m/partition with quorum$/ ) {
                $self->{output}->output_add(severity => 'CRITICAL', 
                                            short_msg => "No Quorum");
            }
        } elsif ($line =~ /^offline:\s*\[\s*(\S.*?)\s*\]/i) {
            # Count offline nodes
            my @offline = split( /\s+/, $1 );
            my $numoffline = scalar @offline;
            $self->{output}->output_add(severity => $self->{threshold}, 
                                        short_msg => "$numoffline Nodes Offline");
        } elsif ($line =~ /^node\s+(\S.*):\s*standby/i) {
            push @standby, $1;
        } elsif ($line =~ /\s*([0-9a-zA-Z_\-]+)\s+\(\S+\)\:\s+Started\s+([0-9a-zA-Z_\-]+)/) {
            # Check Resources pos
            if (defined($self->{resources_check}->{$1}) && $self->{resources_check}->{$1} ne $2) {
                $self->{output}->output_add(severity => $self->{threshold}, 
                                            short_msg => "Resource '$1' is on node '$2'");
            }
        } elsif ($line =~ /\s*([0-9a-zA-Z_\-]+)\s+\(\S+\)\:\s+Stopped/) {
            $self->{output}->output_add(severity => $self->{threshold}, 
                                        short_msg => "Resource '$1' Stopped");
        } elsif ($line =~ m/\s*stopped\:\s*\[(.*)\]/i) {
            # Check Master/Slave stopped
            $self->{output}->output_add(severity => $self->{threshold}, 
                                        short_msg => "$1 Stopped");
        } elsif ($line =~ /^Failed actions\:/) {
            # Check Failed Actions
            my $skip = 0;
            foreach (@{$self->{option_results}->{ignore_failed_actions})} {
                if ($line =~ /$_/) {
                    $skip = 1;
                    last;
{'fraction_non_alphanumeric': 0.17078329178941007, 'fraction_numerical': 0.005438477226376614, 'mean_word_length': 1.7780109106168696, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 195, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 44, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4205832', 'n_tokens_mistral': 3739, 'n_tokens_neox': 3570, 'n_words': 1020}