initial commit

This commit is contained in:
allard
2025-11-23 18:58:51 +01:00
commit 376a944abc
1553 changed files with 314731 additions and 0 deletions

4
dev/itop/README.md Executable file
View File

@@ -0,0 +1,4 @@
sudo microk8s kubectl exec itop-66c56dd4bd-bb2t6 -- chown www-data:www-data /var/www/html/conf
exec my-itop /install-toolkit.sh
exec my-itop conf-w
exec my-itop conf-ro

View File

@@ -0,0 +1,19 @@
apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
name: dev-itop
title: Itop (dev)
description: Harbor instance running in Kubernetes
annotations:
backstage.io/kubernetes-label-selector: "app=itop"
links:
- url: https://github.com/AllardKrings/kubernetes/dev/itop
title: itop-configuration
docs:
- url: ./README.md
spec:
type: service
lifecycle: production
owner: group:default/allarddcs
subcomponentOf: component:default/DEV-cluster

View File

@@ -0,0 +1,3 @@
FROM ubuntu
RUN apt update && apt upgrade -y
RUN apt install wget -y

View File

@@ -0,0 +1,2 @@
php webservices/import.php --auth_user=login --auth_pwd=password --csvfile="location.csv"
--charset="UTF-8" --no_localize=1 --class="Location" --reconcialiationkeys="name,org_id->name"

View File

@@ -0,0 +1,135 @@
<?php
class itopApi {
// Define API details
public function __construct() {
$this->itopApi = array(
"url" => "http://itop.alldcs.nl",
"user" => "allard",
"pass" => "Itop01@"
);
}
// Get details function
public function get($class,$key) {
$params['operation'] = 'core/get';
$params['class'] = $class;
$params['key'] = $key;
$execute = $this->execute($params);
RETURN $execute;
}
// Apply stimulus to an object
public function stimulus($param,$fields) {
$params['operation'] = 'core/apply_stimulus';
$params['comment'] = $param['comment'];
$params['stimulus'] = $param['stimulus'];
$params['class'] = $param['class'];
$params['key'] = $param['key'];
$params['fields'] = $fields;
$execute = $this->execute($params);
RETURN $execute;
}
// Hit data to itop server
private function execute($params) {
$param['auth_user'] = $this->itopApi['user'];
$param['auth_pwd'] = $this->itopApi['pass'];
$param['json_data'] = json_encode($params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->itopApi['url']);
curl_setopt($ch, CURLOPT_POST, count($param));
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($param));
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = json_decode(curl_exec($ch),true);
curl_close($ch);
RETURN $result; // Returning data on array format
}
// Testing purpose function
public function test() {
echo $this->itopApi['url'];
}
}
?>

View File

@@ -0,0 +1,12 @@
{
"operation":"core/create",
"comment":"Synchronization from blah...",
"class":"RoutineChange",
"fields":
{
"org_id":"SELECT Organization WHERE name = 'ALLDCS'",
"caller_id":{"name":"Krings","first_name":"Allard"},
"title":"container",
"description":"container gebouwd"
}
}

View File

@@ -0,0 +1,28 @@
#!/bin/bash
##################################################################################
# #
# Example script for creating a UserRequest ticket via the REST/JSON webservices #
# #
##################################################################################
# iTop location and credentials, change them to suit your iTop installation
ITOP_URL="https://itop.alldcs.nl"
ITOP_USER="tekton"
ITOP_PWD="Itop01@@@"
ORGANIZATION="0002"
TITLE="Change registration"
DESCRIPTION="Container created"
CALLER="0001"
COMMENT="commentaar"
CHANGE="RoutineChange"
# Let's create the ticket via the REST/JSON API
JSON_DATA='{"operation":"core/create", "class":"'"${CHANGE}"'", "fields": {"org_id":"'"${ORGANIZATION}"'", "title":"'"$TITLE"'", "description":"'"$DESCRIPTION"'"}, "caller": "'"$CALLER"'", "comment": "'"$COMMENT"'"}'
RESULT=`wget -q --post-data='auth_user='"${ITOP_USER}"'&auth_pwd='"${ITOP_PWD}"'&json_data='"${JSON_DATA}" --no-check-certificate -O - "${ITOP_URL}/webservices/rest.php?version=1.0"`
PATTERN='"key":"([0-9])+"'
if [[ $RESULT =~ $PATTERN ]]; then
echo "Change created successfully"
else
echo "ERROR: failed to create change"
echo $RESULT
exit 1
fi

View File

@@ -0,0 +1 @@
curl -X POST -F 'version=1.3' -F 'auth_user=allard' -F 'auth_pwd=Itop01@@@' http://itop.alldcs.nl/webservices/rest.php -F 'json_data=@./change.json'

View File

@@ -0,0 +1,3 @@
FROM ubuntu
RUN apt update && apt upgrade -y
RUN apt install wget -y

View File

@@ -0,0 +1,2 @@
php webservices/import.php --auth_user=login --auth_pwd=password --csvfile="location.csv"
--charset="UTF-8" --no_localize=1 --class="Location" --reconcialiationkeys="name,org_id->name"

View File

@@ -0,0 +1,135 @@
<?php
class itopApi {
// Define API details
public function __construct() {
$this->itopApi = array(
"url" => "http://itop.alldcs.nl",
"user" => "allard",
"pass" => "Itop01@"
);
}
// Get details function
public function get($class,$key) {
$params['operation'] = 'core/get';
$params['class'] = $class;
$params['key'] = $key;
$execute = $this->execute($params);
RETURN $execute;
}
// Apply stimulus to an object
public function stimulus($param,$fields) {
$params['operation'] = 'core/apply_stimulus';
$params['comment'] = $param['comment'];
$params['stimulus'] = $param['stimulus'];
$params['class'] = $param['class'];
$params['key'] = $param['key'];
$params['fields'] = $fields;
$execute = $this->execute($params);
RETURN $execute;
}
// Hit data to itop server
private function execute($params) {
$param['auth_user'] = $this->itopApi['user'];
$param['auth_pwd'] = $this->itopApi['pass'];
$param['json_data'] = json_encode($params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->itopApi['url']);
curl_setopt($ch, CURLOPT_POST, count($param));
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($param));
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = json_decode(curl_exec($ch),true);
curl_close($ch);
RETURN $result; // Returning data on array format
}
// Testing purpose function
public function test() {
echo $this->itopApi['url'];
}
}
?>

View File

@@ -0,0 +1,12 @@
{
"operation":"core/create",
"comment":"Synchronization from blah...",
"class":"RoutineChange",
"fields":
{
"org_id":"SELECT Organization WHERE name = 'ALLDCS'",
"caller_id":{"name":"Krings","first_name":"Allard"},
"title":"container",
"description":"container gebouwd"
}
}

View File

@@ -0,0 +1,27 @@
#!/bin/bash
##################################################################################
# #
# Example script for creating a UserRequest ticket via the REST/JSON webservices #
# #
##################################################################################
# iTop location and credentials, change them to suit your iTop installation
ITOP_URL="https://itop.alldcs.nl"
ITOP_USER="allard"
ITOP_PWD="Itop01@@@"
ORGANIZATION="0001"
TITLE="UserRequest"
DESCRIPTION="Container created"
CALLER="0001"
COMMENT="commentaar"
CHANGE="RoutineChange"
# Let's create the ticket via the REST/JSON API
JSON_DATA='{"operation":"core/create", "class":"'"${CHANGE}"'", "fields": {"org_id":"'"${ORGANIZATION}"'", "title":"'"$TITLE"'", "description":"'"$DESCRIPTION"'"}, "caller": "'"$CALLER"'", "comment": "'"$COMMENT"'"}'
RESULT=`wget -q --post-data='auth_user='"${ITOP_USER}"'&auth_pwd='"${ITOP_PWD}"'&json_data='"${JSON_DATA}" --no-check-certificate -O - "${ITOP_URL}/webservices/rest.php?version=1.0"`
#PATTERN='"key":"([0-9])+"'
#if [[ $RESULT =~ $PATTERN ]]; then
# echo "Change created successfully"
# else
# echo "ERROR: failed to create change"
# echo $RESULT
#fi

View File

@@ -0,0 +1 @@
curl -X POST -F 'version=1.3' -F 'auth_user=allard' -F 'auth_pwd=Itop01@@@' http://itop.alldcs.nl/webservices/rest.php -F 'json_data=@./change.json'

View File

@@ -0,0 +1,13 @@
{
"operation":"core/create",
"comment":"Synchronization from blah...",
"class":"UserRequest",
"output_fields":"id, friendlyname",
"fields":
{
"org_id":"SELECT Organization WHERE name = 'ALLDCS'",
"caller_id":{"name":"Krings","first_name":"Allard"},
"title":"issue blah",
"description":"something happened"
}
}

View File

@@ -0,0 +1,3 @@
Last Name,Status,Organization->Name,Email,Phone,Notification,Function,First Name
"Monet","Active","Demo","monet@demo.com","","yes","","Claude"
"Flaubert","Active","IT Department","flaubert@it.com","","yes","","Gustave"
1 Last Name Status Organization->Name Email Phone Notification Function First Name
2 Monet Active Demo monet@demo.com yes Claude
3 Flaubert Active IT Department flaubert@it.com yes Gustave

View File

@@ -0,0 +1,65 @@
#!/bin/bash
##################################################################################
# #
# Example script for creating a UserRequest ticket via the REST/JSON webservices #
# #
##################################################################################
# iTop location and credentials, change them to suit your iTop installation
ITOP_URL="https://itop.alldcs.nl"
ITOP_USER="allard"
ITOP_PWD="Itop01@@@"
# Parameters checking, see below for default values
if [ "$1" == "" ]; then
echo "Missing parameter 1: host"
exit -1
else
HOST="$1"
fi
if [ "$2" == "" ]; then
echo "Missing parameter 2: Service"
exit -1
else
SERVICE="$2"
fi
if [ "$3" == "" ]; then
echo "Missing parameter 3: Service Status"
exit -1
else
SERVICE_STATUS="$3"
fi
if [ "$4" == "" ]; then
echo "Missing parameter 4: Service State Type"
exit -1
else
SERVICE_STATUS_TYPE="$4"
fi
# Default values, adapt them to your configuration
TICKET_CLASS="UserRequest"
ORGANIZATION="SELECT Organization JOIN FunctionalCI AS CI ON CI.org_id=Organization.id WHERE CI.name='"${HOST}"'"
TITLE="Service Down on $1"
DESCRIPTION="The service $SERVICE is in state $SERVICE_STATUS on $HOST"
# Let's create the ticket via the REST/JSON API
if [[ ( "$SERVICE_STATUS" != "OK" ) && ( "$SERVICE_STATUS" != "UP" ) && ( "$SERVICE_STATUS_TYPE" == "HARD" ) ]]; then
CIS_LIST='[{"functionalci_id":"SELECT FunctionalCI WHERE name=\"'"$1"'\"", "impact_code": "manual"}]'
JSON_DATA='{"operation":"core/create", "class":"'"${TICKET_CLASS}"'", "fields": {"functionalcis_list":'"${CIS_LIST}"', "org_id":"'"${ORGANIZATION}"'", "title":"'"$TITLE"'", "description":"'"$DESCRIPTION"'"}, "comment": "Created by the Monitoring", "output_fields": "id"}'
RESULT=`wget -q --post-data='auth_user='"${ITOP_USER}"'&auth_pwd='"${ITOP_PWD}"'&json_data='"${JSON_DATA}" --no-check-certificate -O - "${ITOP_URL}/webservices/rest.php?version=1.0"`
PATTERN='"key":"([0-9])+"'
if [[ $RESULT =~ $PATTERN ]]; then
echo "Ticket created successfully"
else
echo "ERROR: failed to create ticket"
echo $RESULT
fi
else
echo "Service State Type != HARD, doing nothing"
fi

View File

@@ -0,0 +1,8 @@
#!/usr/bin/env bash
HTTP POST itop.alldcs.nl/webservices/rest.php?version=1.3
auth_user=Itop_admin
auth_pwd=Itop01@
json_data=
{
"operation": "list_operations"
}

View File

@@ -0,0 +1,73 @@
<?php
include('apifunction.php');
$itopApi = new itopApi;
/** GET Function Test **/
/**
$api = $itopApi->get("Incident","1620");
echo "<pre>";
print_r($api);
echo "</pre>";
**/
/** ASSIGN (Stimulus) Function Test **/
/* $param['comment'] = "Assigned from API";
$param['stimulus'] = "ev_assign";
$param['class'] = "Incident";
$param['key'] = "1620";
$fields['team_id'] = "39";
$fields['agent_id'] = "3";
$api = $itopApi->stimulus($param,$fields);
echo "<pre>";
print_r($api);
echo "</pre>"; */
/** RESOLVE (Stimulus) Function Test **/
/* $param['comment'] = "Resolved from API";
$param['stimulus'] = "ev_resolve";
$param['class'] = "Incident";
$param['key'] = "1653";
$fields['solution'] = "PC Sudah terinstall iReap";
$api = $itopApi->stimulus($param,$fields);
echo "<pre>";
print_r($api);
echo "</pre>"; */
?>

View File

@@ -0,0 +1,13 @@
{
"operation":"core/create",
"comment":"Synchronization from blah...",
"class":"UserRequest",
"output_fields":"id, friendlyname",
"fields":
{
"org_id":"SELECT Organization WHERE name = 'ALLDCS'",
"caller_id":{"name":"Krings","first_name":"Allard"},
"title":"issue blah",
"description":"something happened"
}
}

View File

@@ -0,0 +1,3 @@
Last Name,Status,Organization->Name,Email,Phone,Notification,Function,First Name
"Monet","Active","Demo","monet@demo.com","","yes","","Claude"
"Flaubert","Active","IT Department","flaubert@it.com","","yes","","Gustave"
1 Last Name Status Organization->Name Email Phone Notification Function First Name
2 Monet Active Demo monet@demo.com yes Claude
3 Flaubert Active IT Department flaubert@it.com yes Gustave

View File

@@ -0,0 +1,65 @@
#!/bin/bash
##################################################################################
# #
# Example script for creating a UserRequest ticket via the REST/JSON webservices #
# #
##################################################################################
# iTop location and credentials, change them to suit your iTop installation
ITOP_URL="https://itop.alldcs.nl"
ITOP_USER="allard"
ITOP_PWD="Itop01@@@"
# Parameters checking, see below for default values
if [ "$1" == "" ]; then
echo "Missing parameter 1: host"
exit -1
else
HOST="$1"
fi
if [ "$2" == "" ]; then
echo "Missing parameter 2: Service"
exit -1
else
SERVICE="$2"
fi
if [ "$3" == "" ]; then
echo "Missing parameter 3: Service Status"
exit -1
else
SERVICE_STATUS="$3"
fi
if [ "$4" == "" ]; then
echo "Missing parameter 4: Service State Type"
exit -1
else
SERVICE_STATUS_TYPE="$4"
fi
# Default values, adapt them to your configuration
TICKET_CLASS="UserRequest"
ORGANIZATION="SELECT Organization JOIN FunctionalCI AS CI ON CI.org_id=Organization.id WHERE CI.name='"${HOST}"'"
TITLE="Service Down on $1"
DESCRIPTION="The service $SERVICE is in state $SERVICE_STATUS on $HOST"
# Let's create the ticket via the REST/JSON API
if [[ ( "$SERVICE_STATUS" != "OK" ) && ( "$SERVICE_STATUS" != "UP" ) && ( "$SERVICE_STATUS_TYPE" == "HARD" ) ]]; then
CIS_LIST='[{"functionalci_id":"SELECT FunctionalCI WHERE name=\"'"$1"'\"", "impact_code": "manual"}]'
JSON_DATA='{"operation":"core/create", "class":"'"${TICKET_CLASS}"'", "fields": {"functionalcis_list":'"${CIS_LIST}"', "org_id":"'"${ORGANIZATION}"'", "title":"'"$TITLE"'", "description":"'"$DESCRIPTION"'"}, "comment": "Created by the Monitoring", "output_fields": "id"}'
RESULT=`wget -q --post-data='auth_user='"${ITOP_USER}"'&auth_pwd='"${ITOP_PWD}"'&json_data='"${JSON_DATA}" --no-check-certificate -O - "${ITOP_URL}/webservices/rest.php?version=1.0"`
PATTERN='"key":"([0-9])+"'
if [[ $RESULT =~ $PATTERN ]]; then
echo "Ticket created successfully"
else
echo "ERROR: failed to create ticket"
echo $RESULT
fi
else
echo "Service State Type != HARD, doing nothing"
fi

View File

@@ -0,0 +1,8 @@
#!/usr/bin/env bash
HTTP POST itop.alldcs.nl/webservices/rest.php?version=1.3
auth_user=Itop_admin
auth_pwd=Itop01@
json_data=
{
"operation": "list_operations"
}

View File

@@ -0,0 +1,73 @@
<?php
include('apifunction.php');
$itopApi = new itopApi;
/** GET Function Test **/
/**
$api = $itopApi->get("Incident","1620");
echo "<pre>";
print_r($api);
echo "</pre>";
**/
/** ASSIGN (Stimulus) Function Test **/
/* $param['comment'] = "Assigned from API";
$param['stimulus'] = "ev_assign";
$param['class'] = "Incident";
$param['key'] = "1620";
$fields['team_id'] = "39";
$fields['agent_id'] = "3";
$api = $itopApi->stimulus($param,$fields);
echo "<pre>";
print_r($api);
echo "</pre>"; */
/** RESOLVE (Stimulus) Function Test **/
/* $param['comment'] = "Resolved from API";
$param['stimulus'] = "ev_resolve";
$param['class'] = "Incident";
$param['key'] = "1653";
$fields['solution'] = "PC Sudah terinstall iReap";
$api = $itopApi->stimulus($param,$fields);
echo "<pre>";
print_r($api);
echo "</pre>"; */
?>

118
dev/itop/itop.yaml Executable file
View File

@@ -0,0 +1,118 @@
apiVersion: v1
kind: PersistentVolume
metadata:
name: itop-pv
spec:
storageClassName: ""
capacity:
storage: 1Gi
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Retain
mountOptions:
- hard
- nfsvers=4.1
nfs:
server: 192.168.2.110
path: /mnt/nfs_share/itop/
readOnly: false
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: itop-pvc
namespace: itop
spec:
storageClassName: ""
volumeName: itop-pv
accessModes:
- ReadWriteMany
volumeMode: Filesystem
resources:
requests:
storage: 1Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: itop
namespace: itop
labels:
app: itop
spec:
replicas: 1
selector:
matchLabels:
app: itop
template:
metadata:
labels:
app: itop
spec:
containers:
- name: itop
image: allardkrings/itop:external
env:
- name: ITOP_DB_HOST
value: mariadb.mariadb
- name: ITOP_DB_NAME
value: itop
- name: ITOP_DB_USER
value: itop
- name: ITOP_DB_PASS
value: itop
volumeMounts:
- mountPath: /var/www/html/conf
name: itop
subPath: conf
volumes:
- name: itop
persistentVolumeClaim:
claimName: itop-pvc
---
apiVersion: v1
kind: Service
metadata:
name: itop
namespace: itop
spec:
selector:
app.kubernetes.io/name: itop
ports:
- protocol: TCP
port: 80
targetPort: 80
selector:
app: itop
---
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
name: itop-http
namespace: itop
spec:
entryPoints:
- web
routes:
- match: Host(`itop-dev.allarddcs.nl`)
kind: Rule
services:
- name: itop
port: 80
---
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
name: itop-tls
namespace: itop
spec:
entryPoints:
- websecure
routes:
- match: Host(`itop-dev.allarddcs.nl`)
kind: Rule
services:
- name: itop
port: 80
tls:
certResolver: letsencrypt

8
dev/itop/test.sh Executable file
View File

@@ -0,0 +1,8 @@
#!/usr/bin/env bash
HTTP POST itop.alldcs.nl/webservices/rest.php?version=1.3
auth_user=Itop_admin
auth_pwd=Itop01@
json_data=
{
"operation": "list_operations"
}