~asanjar/charms/trusty/hdp-hadoop/test

« back to all changes in this revision

Viewing changes to hooks/test/hdp_scripts/hdp_manual_install_rpm_helper_files-2.1.1.385/configuration_files/nagios/plugins/check_name_dir_status.php

  • Committer: amir sanjar
  • Date: 2014-07-21 19:53:44 UTC
  • Revision ID: amir.sanjar@canonical.com-20140721195344-a23z0lrebqzhl167
namenode & data node initialization

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
/*
3
 
 * Licensed to the Apache Software Foundation (ASF) under one
4
 
 * or more contributor license agreements.  See the NOTICE file
5
 
 * distributed with this work for additional information
6
 
 * regarding copyright ownership.  The ASF licenses this file
7
 
 * to you under the Apache License, Version 2.0 (the
8
 
 * "License"); you may not use this file except in compliance
9
 
 * with the License.  You may obtain a copy of the License at
10
 
 *
11
 
 *     http://www.apache.org/licenses/LICENSE-2.0
12
 
 *
13
 
 * Unless required by applicable law or agreed to in writing, software
14
 
 * distributed under the License is distributed on an "AS IS" BASIS,
15
 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 
 * See the License for the specific language governing permissions and
17
 
 * limitations under the License.
18
 
 */
19
 
 
20
 
/* This plugin makes call to namenode, get the jmx-json document
21
 
 * check the NameDirStatuses to find any offline (failed) directories
22
 
 * check_jmx -H hostaddress -p port
23
 
 */
24
 
 
25
 
  $options = getopt ("h:p:");
26
 
  if (!array_key_exists('h', $options) || !array_key_exists('p', $options)) {
27
 
    usage();
28
 
    exit(3);
29
 
  }
30
 
 
31
 
  $host=$options['h'];
32
 
  $port=$options['p'];
33
 
 
34
 
  /* Get the json document */
35
 
  $json_string = file_get_contents("http://".$host.":".$port."/jmx?qry=Hadoop:service=NameNode,name=NameNodeInfo");
36
 
  $json_array = json_decode($json_string, true);
37
 
  $object = $json_array['beans'][0];
38
 
  if ($object['NameDirStatuses'] == "") {
39
 
    echo "WARNING: NameNode directory status not available via http://".$host.":".$port."/jmx url" . "\n";
40
 
    exit(1);
41
 
  }
42
 
  $NameDirStatuses = json_decode($object['NameDirStatuses'], true);
43
 
  $failed_dir_count = count($NameDirStatuses['failed']);
44
 
  $out_msg = "CRITICAL: Offline NameNode directories: ";
45
 
  if ($failed_dir_count > 0) {
46
 
    foreach ($NameDirStatuses['failed'] as $key => $value) {
47
 
      $out_msg = $out_msg . $key . ":" . $value . ", ";
48
 
    }
49
 
    echo $out_msg . "\n";
50
 
    exit (2);
51
 
  }
52
 
  echo "OK: All NameNode directories are active" . "\n";
53
 
  exit(0);
54
 
 
55
 
  /* print usage */
56
 
  function usage () {
57
 
    echo "Usage: $0 -h <host> -p port\n";
58
 
  }
59
 
?>