mirror of https://github.com/Icinga/icinga2.git
Merge pull request #7866 from Icinga/feature/cleanup-repo
Remove contrib/ directory
This commit is contained in:
commit
300287664e
|
@ -1 +0,0 @@
|
|||
# Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+
|
|
@ -1,6 +0,0 @@
|
|||
Icinga 2 Contrib files
|
||||
======================
|
||||
|
||||
This directory contains various unsupported scripts. Chances are that they're
|
||||
either completely broken or at least need some changes to work with the most
|
||||
recent version of Icinga 2.
|
|
@ -1,131 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
# Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+
|
||||
|
||||
import sys
|
||||
import subprocess
|
||||
import socket
|
||||
import urlparse
|
||||
import requests
|
||||
import json
|
||||
from xml.dom.minidom import parse
|
||||
|
||||
api_url = "https://localhost:5665/"
|
||||
api_user = "root"
|
||||
api_password = "root"
|
||||
|
||||
if len(sys.argv) < 2:
|
||||
print "Syntax: %s <xml-file> [<xml-file> ...]" % (sys.argv[0])
|
||||
sys.exit(1)
|
||||
|
||||
tcp_service_commands = {
|
||||
'ssh': 'ssh',
|
||||
'http': 'http',
|
||||
'smtp': 'smtp',
|
||||
'ssmtp': 'ssmtp'
|
||||
}
|
||||
|
||||
udp_service_commands = {
|
||||
'ntp': 'ntp_time',
|
||||
'snmp': 'snmp-uptime'
|
||||
}
|
||||
|
||||
hosts = {}
|
||||
|
||||
def process_host(host_element):
|
||||
global hosts
|
||||
|
||||
status = "down"
|
||||
|
||||
for status_element in host_element.getElementsByTagName("status"):
|
||||
status = status_element.getAttribute("state")
|
||||
|
||||
if status != "up":
|
||||
return
|
||||
|
||||
for address_element in host_element.getElementsByTagName("address"):
|
||||
if not address_element.getAttribute("addrtype") in [ "ipv4", "ipv6" ]:
|
||||
continue
|
||||
|
||||
address = address_element.getAttribute("addr")
|
||||
break
|
||||
|
||||
name = address
|
||||
|
||||
for hostname_element in host_element.getElementsByTagName("hostname"):
|
||||
name = hostname_element.getAttribute("name")
|
||||
|
||||
try:
|
||||
services = hosts[name]["services"]
|
||||
except:
|
||||
services = {}
|
||||
|
||||
for port_element in host_element.getElementsByTagName("port"):
|
||||
state = "closed"
|
||||
|
||||
for state_element in port_element.getElementsByTagName("state"):
|
||||
state = state_element.getAttribute("state")
|
||||
|
||||
if state != "open":
|
||||
continue
|
||||
|
||||
port = int(port_element.getAttribute("portid"))
|
||||
protocol = port_element.getAttribute("protocol")
|
||||
|
||||
try:
|
||||
serv = socket.getservbyport(port, protocol)
|
||||
except:
|
||||
serv = str(port)
|
||||
|
||||
try:
|
||||
if protocol == "tcp":
|
||||
command = tcp_service_commands[serv]
|
||||
elif protocol == "udp":
|
||||
command = udp_service_commands[serv]
|
||||
else:
|
||||
raise "Unknown protocol."
|
||||
except:
|
||||
command = protocol
|
||||
|
||||
if command == "udp":
|
||||
continue
|
||||
|
||||
services[serv] = { "command": command, "port": port }
|
||||
|
||||
hosts[name] = { "name": name, "address": address, "services": services }
|
||||
|
||||
def create_host(host):
|
||||
global api_url, api_user, api_password
|
||||
|
||||
req = {
|
||||
"templates": [ "discovered-host" ],
|
||||
"attrs": {
|
||||
"address": host["address"]
|
||||
}
|
||||
}
|
||||
|
||||
headers = {"Accept": "application/json"}
|
||||
url = urlparse.urljoin(api_url, "v1/objects/hosts/%s" % (host["name"]))
|
||||
requests.put(url, headers=headers, auth=(api_user, api_password), data=json.dumps(req), verify=False)
|
||||
|
||||
for serv, service in host["services"].iteritems():
|
||||
req = {
|
||||
"templates": [ "discovered-service" ],
|
||||
"attrs": {
|
||||
"vars.%s_port" % (service["command"]): service["port"],
|
||||
"check_command": service["command"],
|
||||
}
|
||||
}
|
||||
|
||||
headers = {"Accept": "application/json"}
|
||||
url = urlparse.urljoin(api_url, "v1/objects/services/%s!%s" % (host["name"], serv))
|
||||
requests.put(url, headers=headers, auth=(api_user, api_password), data=json.dumps(req), verify=False)
|
||||
|
||||
for arg in sys.argv[1:]:
|
||||
# Expects XML output from 'nmap -oX'
|
||||
dom = parse(arg)
|
||||
|
||||
for host in dom.getElementsByTagName("host"):
|
||||
process_host(host)
|
||||
|
||||
for host in hosts.values():
|
||||
create_host(host)
|
|
@ -1,117 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
# Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+
|
||||
|
||||
import sys
|
||||
import subprocess
|
||||
import socket
|
||||
from xml.dom.minidom import parse
|
||||
|
||||
if len(sys.argv) < 2:
|
||||
print "Syntax: %s <xml-file> [<xml-file> ...]" % (sys.argv[0])
|
||||
sys.exit(1)
|
||||
|
||||
tcp_service_commands = {
|
||||
'ssh': 'ssh',
|
||||
'http': 'http_ip',
|
||||
'https': 'https_ip',
|
||||
'smtp': 'smtp',
|
||||
'ssmtp': 'ssmtp'
|
||||
}
|
||||
|
||||
udp_service_commands = {
|
||||
'ntp': 'ntp_time',
|
||||
'snmp': 'snmp-uptime'
|
||||
}
|
||||
|
||||
hosts = {}
|
||||
|
||||
def process_host(host_element):
|
||||
global hosts
|
||||
|
||||
status = "down"
|
||||
|
||||
for status_element in host_element.getElementsByTagName("status"):
|
||||
status = status_element.getAttribute("state")
|
||||
|
||||
if status != "up":
|
||||
return
|
||||
|
||||
for address_element in host_element.getElementsByTagName("address"):
|
||||
if not address_element.getAttribute("addrtype") in [ "ipv4", "ipv6" ]:
|
||||
continue
|
||||
|
||||
address = address_element.getAttribute("addr")
|
||||
break
|
||||
|
||||
name = address
|
||||
|
||||
for hostname_element in host_element.getElementsByTagName("hostname"):
|
||||
name = hostname_element.getAttribute("name")
|
||||
|
||||
try:
|
||||
services = hosts[name]["services"]
|
||||
except:
|
||||
services = {}
|
||||
|
||||
for port_element in host_element.getElementsByTagName("port"):
|
||||
state = "closed"
|
||||
|
||||
for state_element in port_element.getElementsByTagName("state"):
|
||||
state = state_element.getAttribute("state")
|
||||
|
||||
if state != "open":
|
||||
continue
|
||||
|
||||
port = int(port_element.getAttribute("portid"))
|
||||
protocol = port_element.getAttribute("protocol")
|
||||
|
||||
try:
|
||||
serv = socket.getservbyport(port, protocol)
|
||||
except:
|
||||
serv = str(port)
|
||||
|
||||
try:
|
||||
if protocol == "tcp":
|
||||
command = tcp_service_commands[serv]
|
||||
elif protocol == "udp":
|
||||
command = udp_service_commands[serv]
|
||||
else:
|
||||
raise "Unknown protocol."
|
||||
except:
|
||||
command = protocol
|
||||
|
||||
if command == "udp":
|
||||
continue
|
||||
|
||||
services[serv] = { "command": command, "port": port }
|
||||
|
||||
hosts[name] = { "name": name, "address": address, "services": services }
|
||||
|
||||
def print_host(host):
|
||||
print "object Host \"%s\" {" % (host["name"])
|
||||
print "\timport \"discovered-host\","
|
||||
print ""
|
||||
print "\taddress = \"%s\"," % (host["address"])
|
||||
print "}"
|
||||
print ""
|
||||
|
||||
for serv, service in host["services"].iteritems():
|
||||
print "object Service \"%s\" {" % (serv)
|
||||
print "\timport \"discovered-service\","
|
||||
print ""
|
||||
print "\thost_name = \"%s\"" % (host["name"])
|
||||
print "\tcheck_command = \"%s\"," % (service["command"])
|
||||
print ""
|
||||
print "\tvars.port = %s" % (service["port"])
|
||||
print "}"
|
||||
print ""
|
||||
|
||||
for arg in sys.argv[1:]:
|
||||
# Expects XML output from 'nmap -oX'
|
||||
dom = parse(arg)
|
||||
|
||||
for host in dom.getElementsByTagName("host"):
|
||||
process_host(host)
|
||||
|
||||
for host in hosts.values():
|
||||
print_host(host)
|
|
@ -1,3 +0,0 @@
|
|||
i2tcl.so: i2tcl.cpp i2tcl.hpp
|
||||
swig -c++ -o i2tcl_wrap.cpp i2tcl.hpp
|
||||
g++ -g -std=c++11 -I/usr/include/tcl8.5 -shared -fpic -Iicinga2/lib -Iicinga2/build -Iicinga2/build/lib -L/opt/icinga2/lib/icinga2 -lbase -lconfig -Wl,-rpath=/opt/icinga2/lib/icinga2 -o i2tcl.so i2tcl_wrap.cpp i2tcl.cpp
|
|
@ -1 +0,0 @@
|
|||
This is the source code for the 'i2eval' IRC bot that's on #icinga and #icinga-devel.
|
|
@ -1,176 +0,0 @@
|
|||
#include "i2tcl.hpp"
|
||||
#include "config/configcompiler.hpp"
|
||||
#include "config/configcompilercontext.hpp"
|
||||
#include "base/function.hpp"
|
||||
#include "base/json.hpp"
|
||||
#include "base/application.hpp"
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
using namespace icinga;
|
||||
|
||||
static bool l_Init_Called;
|
||||
static Tcl_Interp *l_Interp;
|
||||
static Tcl_Encoding l_Encoding;
|
||||
static std::map<String, String> l_Lines;
|
||||
static int l_NextLine = 1;
|
||||
|
||||
static Value i2_call_tcl(const String& command, const String& mtype, const std::vector<Value>& args)
|
||||
{
|
||||
Tcl_Obj **objv = new Tcl_Obj *[args.size() + 1];
|
||||
objv[0] = Tcl_NewStringObj(command.CStr(), -1);
|
||||
Tcl_IncrRefCount(objv[0]);
|
||||
|
||||
for (size_t i = 0; i < args.size(); i++) {
|
||||
Tcl_DString dsText;
|
||||
String arg = static_cast<String>(args[i]);
|
||||
Tcl_ExternalToUtfDString(l_Encoding, arg.CStr(), -1, &dsText);
|
||||
objv[i + 1] = Tcl_NewStringObj(Tcl_DStringValue(&dsText), Tcl_DStringLength(&dsText));
|
||||
Tcl_DStringFree(&dsText);
|
||||
Tcl_IncrRefCount(objv[i + 1]);
|
||||
}
|
||||
|
||||
int code = Tcl_EvalObjv(l_Interp, args.size() + 1, objv, TCL_EVAL_GLOBAL);
|
||||
|
||||
Tcl_Obj *result = Tcl_GetObjResult(l_Interp);
|
||||
|
||||
for (size_t i = 0; i < args.size() + 1; i++)
|
||||
Tcl_DecrRefCount(objv[i]);
|
||||
|
||||
delete [] objv;
|
||||
|
||||
if (code == TCL_ERROR)
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error("An error occurred in the TCL script"));
|
||||
|
||||
Value vresult;
|
||||
|
||||
if (mtype == "list") {
|
||||
Array::Ptr arr = new Array();
|
||||
|
||||
int len;
|
||||
if (Tcl_ListObjLength(l_Interp, result, &len) != TCL_OK)
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument("TCL proc returned something that is not a list"));
|
||||
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
Tcl_Obj *obj;
|
||||
Tcl_ListObjIndex(l_Interp, result, i, &obj);
|
||||
|
||||
const char* strObj = Tcl_GetString(obj);
|
||||
|
||||
Tcl_DString dsObj;
|
||||
arr->Add(Tcl_UtfToExternalDString(l_Encoding, strObj, -1, &dsObj));
|
||||
Tcl_DStringFree(&dsObj);
|
||||
}
|
||||
|
||||
vresult = arr;
|
||||
} else if (mtype == "null") {
|
||||
/* Nothing to do here */
|
||||
} else if (mtype == "number") {
|
||||
const char* strResult = Tcl_GetString(result);
|
||||
vresult = Convert::ToDouble(strResult);
|
||||
} else if (mtype == "bool") {
|
||||
const char* strResult = Tcl_GetString(result);
|
||||
vresult = Convert::ToBool(Convert::ToLong(strResult));
|
||||
} else {
|
||||
const char* strResult = Tcl_GetString(result);
|
||||
|
||||
Tcl_DString dsResult;
|
||||
vresult = Tcl_UtfToExternalDString(l_Encoding, strResult, -1, &dsResult);
|
||||
Tcl_DStringFree(&dsResult);
|
||||
}
|
||||
|
||||
|
||||
return vresult;
|
||||
}
|
||||
|
||||
void i2_register_command(const char *icmd, const char *tcmd, const char *mtype, Tcl_Interp *interp)
|
||||
{
|
||||
Function::Ptr sf = new Function(icmd, boost::bind(i2_call_tcl, String(tcmd), String(mtype), _1));
|
||||
ScriptGlobal::Set(icmd, sf);
|
||||
}
|
||||
|
||||
void *i2_new_frame(Tcl_Interp *interp)
|
||||
{
|
||||
if (!l_Init_Called) {
|
||||
l_Init_Called = true;
|
||||
l_Encoding = Tcl_GetEncoding(l_Interp, "ISO8859-1");
|
||||
Application::InitializeBase();
|
||||
}
|
||||
|
||||
ScriptFrame *frame = new ScriptFrame();
|
||||
frame->Self = ScriptGlobal::GetGlobals();
|
||||
return frame;
|
||||
}
|
||||
|
||||
void i2_free_frame(void *frame, Tcl_Interp *interp)
|
||||
{
|
||||
delete reinterpret_cast<ScriptFrame *>(frame);
|
||||
}
|
||||
|
||||
char *i2_eval(void *uframe, const char *text, Tcl_Interp *interp)
|
||||
{
|
||||
std::ostringstream msgbuf;
|
||||
Expression *expr;
|
||||
ScriptFrame *frame = reinterpret_cast<ScriptFrame *>(uframe);
|
||||
|
||||
l_Interp = interp;
|
||||
|
||||
try {
|
||||
String lineNum = Convert::ToString(l_NextLine);
|
||||
l_NextLine++;
|
||||
|
||||
String fileName = "<" + lineNum + ">";
|
||||
l_Lines[fileName] = text;
|
||||
|
||||
expr = ConfigCompiler::CompileText(fileName, text);
|
||||
|
||||
if (expr) {
|
||||
Value result = expr->Evaluate(*frame);
|
||||
if (!result.IsObject() || result.IsObjectType<Array>() || result.IsObjectType<Dictionary>())
|
||||
msgbuf << JsonEncode(result);
|
||||
else
|
||||
msgbuf << result;
|
||||
}
|
||||
} catch (const ScriptError& ex) {
|
||||
DebugInfo di = ex.GetDebugInfo();
|
||||
|
||||
if (di.FirstLine != 0) {
|
||||
String text = l_Lines[di.Path];
|
||||
|
||||
std::vector<String> lines;
|
||||
boost::algorithm::split(lines, text, boost::is_any_of("\n"));
|
||||
|
||||
for (int i = di.FirstLine; i <= di.LastLine; i++) {
|
||||
int start, len;
|
||||
|
||||
if (i == di.FirstLine)
|
||||
start = di.FirstColumn;
|
||||
else
|
||||
start = 0;
|
||||
|
||||
if (i == di.LastLine)
|
||||
len = di.LastColumn - di.FirstColumn + 1;
|
||||
else
|
||||
len = lines[i].GetLength();
|
||||
|
||||
String pathInfo = di.Path;
|
||||
if (i != 1)
|
||||
pathInfo += "(" + Convert::ToString(i) + ")";
|
||||
pathInfo += ": ";
|
||||
|
||||
msgbuf << pathInfo << lines[i - 1] << "\n";
|
||||
msgbuf << String(pathInfo.GetLength(), ' ');
|
||||
msgbuf << String(start, ' ') << String(len, '^') << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
msgbuf << ex.what();
|
||||
} catch (const std::exception& ex) {
|
||||
msgbuf << "Error: " << DiagnosticInformation(ex);
|
||||
}
|
||||
|
||||
delete expr;
|
||||
|
||||
std::string str = msgbuf.str();
|
||||
return strdup(str.c_str());
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
#ifdef SWIG
|
||||
%module i2tcl
|
||||
%{
|
||||
#include "i2tcl.hpp"
|
||||
%}
|
||||
|
||||
%typemap(in,numinputs=0) Tcl_Interp *interp {
|
||||
$1 = interp;
|
||||
}
|
||||
|
||||
#endif /* SWIG */
|
||||
|
||||
#include <tcl.h>
|
||||
|
||||
#ifndef I2TCL_H
|
||||
#define I2TCL_H
|
||||
|
||||
void i2_register_command(const char *icmd, const char *tcmd, const char *mtype, Tcl_Interp *interp);
|
||||
void *i2_new_frame(Tcl_Interp *interp);
|
||||
void i2_free_frame(void *frame, Tcl_Interp *interp);
|
||||
char *i2_eval(void *frame, const char *text, Tcl_Interp *interp);
|
||||
|
||||
#endif /* I2TCL_H */
|
|
@ -1,109 +0,0 @@
|
|||
package require http
|
||||
package require tls
|
||||
http::register https 443 [list ::tls::socket -tls1 1]
|
||||
|
||||
load /home/gunnar/i2tcl.so i2tcl
|
||||
|
||||
bind pub - > i2tcl
|
||||
bind pub - >u i2tcl_url
|
||||
bind pub - ^ i2tcl
|
||||
bind pub - ^u i2tcl_url
|
||||
|
||||
if {![info exists ::i2frame]} {
|
||||
set ::i2frame [i2_new_frame]
|
||||
}
|
||||
|
||||
set ::i2chan ""
|
||||
set ::i2nick ""
|
||||
|
||||
i2_register_command irc i2_irc null
|
||||
i2_register_command channels channels list
|
||||
i2_register_command chanlist internalchanlist list
|
||||
i2_register_command getnick getcurrentnick string
|
||||
i2_register_command onchan onchan bool
|
||||
i2_register_command topic topic string
|
||||
i2_register_command topicnick topicnick string
|
||||
i2_register_command topicstamp topicstamp number
|
||||
i2_register_command chanmodes getchanmode string
|
||||
i2_register_command isop isop bool
|
||||
i2_register_command isvoice isvoice bool
|
||||
i2_register_command ishop ishop bool
|
||||
i2_register_command chanhost getchanhost string
|
||||
i2_register_command chanbans chanbans list
|
||||
i2_register_command getnick i2_getnick string
|
||||
i2_register_command getchan i2_getchan string
|
||||
i2_register_command "Internal.run_with_activation_context" i2_null null
|
||||
i2_register_command exit i2_null null
|
||||
|
||||
proc i2_null {} {
|
||||
}
|
||||
|
||||
proc i2_getnick {} {
|
||||
global i2nick
|
||||
return $i2nick
|
||||
}
|
||||
|
||||
proc i2_getchan {} {
|
||||
global i2chan
|
||||
return $i2chan
|
||||
}
|
||||
|
||||
proc i2_irc {message} {
|
||||
global i2chan
|
||||
|
||||
if {[string first "\n" $message] != -1 || [string first "\r" $message] != -1} {
|
||||
return
|
||||
}
|
||||
|
||||
putserv "PRIVMSG $i2chan :$message"
|
||||
}
|
||||
|
||||
proc i2tcl {nick host hand chan arg} {
|
||||
global i2frame i2chan i2nick
|
||||
|
||||
set i2chan $chan
|
||||
set i2nick $nick
|
||||
|
||||
set result [i2_eval $i2frame $arg]
|
||||
|
||||
if {$result == ""} { set result "<no error>" }
|
||||
foreach sline [split $result \n] {
|
||||
putserv "PRIVMSG $chan :( $arg ) = $sline"
|
||||
}
|
||||
}
|
||||
|
||||
proc i2tcl_url {nick host hand chan arg} {
|
||||
global i2frame i2chan i2nick
|
||||
|
||||
set i2chan $chan
|
||||
set i2nick $nick
|
||||
|
||||
if {[catch {set token [http::geturl $arg]} msg]} {
|
||||
putserv "PRIVMSG $chan :HTTP request failed: $msg"
|
||||
http::cleanup $token
|
||||
return
|
||||
}
|
||||
|
||||
if {[http::status $token] != "ok"} {
|
||||
putserv "PRIVMSG $chan :HTTP request failed: [http::error $token]"
|
||||
http::cleanup $token
|
||||
return
|
||||
}
|
||||
|
||||
set rpl [split [http::code $token] " "]
|
||||
|
||||
if {[lindex $rpl 1] != 200} {
|
||||
putserv "PRIVMSG $chan :HTTP request failed: [join [lrange $rpl 1 end]]"
|
||||
http::cleanup $token
|
||||
return
|
||||
}
|
||||
|
||||
set code [http::data $token]
|
||||
http::cleanup $token
|
||||
set result [i2_eval $i2frame $code]
|
||||
|
||||
if {$result == ""} { set result "<no error>" }
|
||||
foreach sline [split $result \n] {
|
||||
putserv "PRIVMSG $chan :( $arg ) = $sline"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue