This file is indexed.

/usr/bin/zabbix-cli-bulk-execution is in zabbix-cli 1.7.0-1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#! /usr/bin/python
#
# Authors:
# rafael@postgresql.org.es / http://www.postgresql.org.es/
#
# Copyright (c) 2014-2015 USIT-University of Oslo
#
# This file is part of Zabbix-cli
# https://github.com/rafaelma/zabbix-cli
#
# Zabbix-CLI 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 3 of the License, or
# (at your option) any later version.
#
# Zabbix-CLI 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 Zabbix-CLI.  If not, see <http://www.gnu.org/licenses/>.

import sys
import os
import argparse
import subprocess

from zabbix_cli.config import *
from zabbix_cli.logs import * 

if __name__ == '__main__':

    try:

        #
        # Process command line parameters
        #

        config_file = ''
        input_file = ''

        parser = argparse.ArgumentParser(prog=sys.argv[0])
        parser.add_argument('--input-file', '-f', metavar='[Filename]', required=True, help='Input file', dest='input_file')
        parser.add_argument('--config','-c', metavar='<config file>', required=False, dest='config_file')

        args = parser.parse_args() 
        input_file = args.input_file

        if args.config_file:
            config_file = args.config_file 
        
        conf = configuration(config_file)

        #
        # If logging is activated, start logging to the file defined
        # with log_file in the config file.
        #

        if conf.logging == 'ON':
            logs = log("zabbix-cli-bulk-execution",config_file)
        else:
            logs = None
            
        if conf.logging == 'ON':
            logs.logger.debug('**** Zabbix-cli-bulk-execution startet. ****')

        # Normalized absolutized version of the pathname if
        # files does not include an absolute path

        if os.path.isabs(input_file) == False:
            input_file = os.path.abspath(input_file) 

        if os.path.exists(input_file):

            if conf.logging == 'ON':
                logs.logger.info('File [%s] exists. Bulk execution of commands defined in this file.',input_file)

            print '[OK] File [' + input_file + '] exists. Bulk execution of commands defined in this file started.'

            #
            # Processing zabbix commands in file
            #

            try:
                with open(input_file,'r') as file:
                    for line in file:
                        zabbix_cli_command = line.strip()

                        command = 'zabbix-cli -o json -C "' + zabbix_cli_command + '"'
                        
                        DEVNULL = open(os.devnull, 'w')
                        proc = subprocess.Popen([command],stdout=DEVNULL,stderr=DEVNULL,shell=True)
                        proc.wait()
                
                        if proc.returncode == 0:
                            if conf.logging == 'ON':
                                logs.logger.info('Zabbix-cli command [%s] executed',command)
                        
                            print '[OK] Zabbix-cli command [' + command +  '] executed'
                                
                        else:
                            if conf.logging == 'ON':
                                logs.logger.error('Zabbix-cli command [%s] could not be executed',command)
                            
                            print '[ERROR] Zabbix-cli command [' + command + '] could not bed executed'
                        
            except Exception as e:

                if conf.logging == 'ON':
                    logs.logger.error('Problems using file [%s] - %s',input_file,e)

                print '[ERROR] Problems using file [' + input_file + '] - ' + str(e)
                sys.exit(1)

        else:
            
            if conf.logging == 'ON':
                logs.logger.info('File [%s] does not exist. Bulk execution of commands aborted.',input_file)

            print '[ERROR] File [' + input_file + '] does not exist. Bulk execution of commands aborted'


        if conf.logging == 'ON':
            logs.logger.debug('**** Zabbix-cli-bulk-execution finished. ****')

    except Exception as e:
        print '\n[ERROR]: %s\n',e
        
        if conf.logging == 'ON':
            logs.logger.error('Problems running zabbix-cli-bulk-execution - %s',e)
        
        print 'Problems running zabbix-cli-bulk-execution - ' + str(e)
        sys.exit(1)