My standard Ubuntu setup command

sudo apt-get update && sudo apt-get upgrade -y && sudo apt-get install htop mc nano

Advertisements

Install Splunk on Ubuntu and hide behind Apache2 Proxy

Problem

  • Hide Splunk behind Apache2
  • Enable .htaccess
  • Ubuntu 16.04 LTS

Solution

Install Splunk

dpkg -i splunk_package_name.deb

/opt/splunk/bin/splunk start –accept-license

For enable this behavior, please set the following in /opt/splunk/etc/system/default/web.conf

root_endpoint=/NAME

Restart Splunk:

/opt/splunk/bin/splunk restart

Start at boot time:

opt/splunk/bin/splunk enable boot-start

Apache

Enable needed modules:

  • sudo a2enmod proxy
  • sudo a2enmod proxy_http

Edit /etc/apache2/sites-available/000-default.conf

<VirtualHost *:80>
ProxyPreserveHost On

ProxyPass / http://127.0.0.1:8000/NAME
ProxyPassReverse / http://127.0.0.1:8000/NAME
</VirtualHost>

Add .htaccess to VirtualHost

<Location /NAME>
AuthType Basic
AuthName “Wrapper auth”
AuthBasicProvider file
AuthUserFile “/PATHTOHTPASSWD/htpasswd”
Require valid-user
</Location>

Restart

sudo systemctl restart apache2

Install Apache2 with SSL/HTTPs on Ubuntu

Problem

  • You need a Apache2 with HTTPs on Ubuntu

Solution

Prepare

sudo apt-get update && sudo apt-get upgrade -y

sudo apt-get install apache2

Create certificate

sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/apache-selfsigned.key -out /etc/ssl/certs/apache-selfsigned.crt

You will be asked for some infomation. Just put in, what you want:

Country Name (2 letter code) [AU]:
State or Province Name (full name) [Some-State]:
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []:
Email Address []:

Optional

Create strong Diffie-Hellman

sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048

SSL Params

SSLCipherSuite EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH
SSLProtocol All -SSLv2 -SSLv3
SSLHonorCipherOrder On
# Disable preloading HSTS for now. You can use the commented out header line that includes
# the “preload” directive if you understand the implications.
#Header always set Strict-Transport-Security “max-age=63072000; includeSubdomains; preload”
Header always set Strict-Transport-Security “max-age=63072000; includeSubdomains”
Header always set X-Frame-Options DENY
Header always set X-Content-Type-Options nosniff
# Requires Apache >= 2.4
SSLCompression off
SSLSessionTickets Off
SSLUseStapling on
SSLStaplingCache “shmcb:logs/stapling-cache(150000)”

Edit /etc/apache2/sites-available/default-ssl.conf

sudo nano /etc/apache2/sites-available/default-ssl.conf

Change to

SSLCertificateFile /etc/ssl/certs/apache-selfsigned.crt
SSLCertificateKeyFile /etc/ssl/private/apache-selfsigned.key

Eanble everything

sudo a2enmod ssl
sudo a2enmod headers
sudo a2ensite default-ssl
sudo a2enconf ssl-params

Restart Apache2

sudo systemctl restart apache2

 

 

 

Install RabbitMQ on Ubuntu 16.04

Problem

  • Install RabbitMQ on Ubuntu Server

Solution

Install Repository

echo ‘deb http://www.rabbitmq.com/debian/ testing main’ | sudo tee /etc/apt/sources.list.d/rabbitmq.list

wget -O- https://www.rabbitmq.com/rabbitmq-release-signing-key.asc | sudo apt-key add –

Install RabbitMQ

sudo apt-get update

sudo apt-get install rabbitmq-server

Status

sudo systemctl status rabbitmq-server

Start RabbitMQ

sudo systemctl start rabbitmq-server

Stop RabbitMQ

sudo systemctl stop rabbitmq-server

Limits

sudo nano /etc/sysctl.conf

Add

fs.file-max = 65536

Run

sudo sysctl -p

Edit

sudo nano /etc/security/limits.conf

Add

* soft nproc 65536
* hard nproc 65536
* soft nofile 65536
* hard nofile 65536
root soft nproc 65536
root hard nproc 65536
root soft nofile 65536
root hard nofile 65536

Edit

sudo nano /etc/pam.d/common-session

Add

session required pam_limits.so

Restart

sudo reboot

Ports

Open Ports: 15672 (Mgmt), 5672 and 5671 (Messages)

Management Plugin

sudo rabbitmq-plugins enable rabbitmq_management

sudo systemctl restart rabbitmq-server

Add Admin

rabbitmqctl add_user admin <<password>>
rabbitmqctl set_user_tags admin administrator
rabbitmqctl set_permissions -p / admin “.*” “.*” “.*”

See Management Site

Open http://<<IP>>:15672

Install iTop on Linux

Problem

  • Install itop on Linux with SELinux

Setting

  • Oracle Linux
  • iTop Version 2.3.4

Solution

Install MySQL

yum install mysql mysql-server

#Set root password
/usr/bin/mysql_secure_installation

mysql – u -p <>

mysql> create database itop;
mysql> create user ‘itop’@’%’ identified by ‘itop-password’;
mysql> grant all privileges on itop.* to ‘itop’@’%’;

mysql> quit;

Install Apache and PHP

yum install httpd php php-mysql php-xml php-soap

systemctl start httpd

Get iTop

wget https://downloads.sourceforge.net/project/itop/itop/2.3.4/iTop-2.3.4-3302.zip?r=https%3A%2F%2Fsourceforge.net%2Fprojects%2Fitop%2Ffiles%2Fitop%2F2.3.4%2F&ts=1502963636&use_mirror=10gbps-io

Files

mv ./web /var/www/itop

cd /var/www/html/itop

mkdir conf
mkdir env-production

chmod 777 conf
chmod 777 data
chmod 777 env-production
chmod 777 log

# If SELinux blocks access
chcon –user system_u –type httpd_sys_content_t -Rv /var/www/html/itop/
# or
sudo setenforce 0

Start install process

Go in your browser and type: http://localhost/itop

Fin

 

Simple HTTP GET with Node.JS

Problem

  • Need a simple HTTP GET call with return value

Solution

var http = require(“http”);
hget(“127.0.0.1”, “8086”,”/exampleCall”,
    function (data) {
        //process your data here
    });
function hget(url, port, path, callbackData) {
    var options = {
        host: url,
        port: port,
        path: path
    };
    callback = function (response) {
        var body = ”;
        response.on(‘data’, function (chunk) {
            body += chunk;
        });
        response.on(‘end’, function () {
            callbackData(body);
        });
    }
    var req = http.request(options, callback).end();
}

101 for REST API with Swagger, ASP.NET and C#

Short summary about my lessons learned for a REST API with Swagger, ASP.NET and C#.

Configuration

Open the file SwaggerConfig.cs. For the first demo, we name our app and enable the UI:

GlobalConfiguration.Configuration
.EnableSwagger(c =>
{
c.SingleApiVersion(“v1”, “API Demonstration”);
})
.EnableSwaggerUi();

SwaggerUI

The SwaggerUI can be found under:

http://localhost:%5BPORT_NUM%5D/swagger

Documentation

If you need documentation for you methods, parameters or controller, you have to enable the XML documentation file:

swagger_doku

Remember the path, you will have to add it to your Swagger configuration. This all the other configurations it should look like this:

GlobalConfiguration.Configuration
.EnableSwagger(c =>
{
c.SingleApiVersion(“v1”, “API Demonstration”);
c.IncludeXmlComments(string.Format(@”{0}\App_Data\API-Test.XML”, System.AppDomain.CurrentDomain.BaseDirectory));
})
.EnableSwaggerUi();

To use the documentation, you can commentary to every method. Remember, you can use HTML formatting.

swagger_docu2

Path Parameters

Path parameters are fixed elements of the URL and are not optional. They can be set by the Route element. Every parameter is configured via {} brackets and have to match with the method parameters:

[HttpGet]
[Route(“test/route/{para1}/{para2}”)]
[SwaggerResponse(HttpStatusCode.OK, Type = typeof(String))]
[SwaggerResponse(HttpStatusCode.BadRequest, Description = “Bad Request”)]
[SwaggerResponse(HttpStatusCode.NotFound, Description = “Not found”)]

public string test(string para1, int para2)
{

The Request URL looks like this:

http://localhost:50283/test/route/Hello/7

Query Parameters

Query parameters are not part of the base URL. If tw want para2 to be a query parameter, just exclude it from the Route:

 

[HttpGet]
[Route(“test/route/{para1}”)]
[SwaggerResponse(HttpStatusCode.OK, Type = typeof(String))]
[SwaggerResponse(HttpStatusCode.BadRequest, Description = “Bad Request”)]
[SwaggerResponse(HttpStatusCode.NotFound, Description = “Not found”)]

public string test(string para1, int para2)
{

The Request URL looks like this:

http://localhost:50283/test/route/Hello?para2=7

(This can also be done with para1)

Optional Parameters

If you want optional parameter, just add a default value for the parameter.

[HttpGet]
[Route(“test/route/{para1}”)]
[SwaggerResponse(HttpStatusCode.OK, Type = typeof(String))]
[SwaggerResponse(HttpStatusCode.BadRequest, Description = “Bad Request”)]
[SwaggerResponse(HttpStatusCode.NotFound, Description = “Not found”)]

public string test(string para1, int para2=0)
{

Validating DateTime

You will get a 404 – Bad Request, if you use DateTime within a path parameter like this:

http://localhost:50283/test/route/2017-05-26T12:30:00

You have to options.

1. Use a query parameter like this: http://localhost:50283/test/route?time=2017-05-26T12:30:00

2. Change your web.config:

<configuration>

<system.web>

<httpRuntime requestPathInvalidCharacters=”” requestValidationMode=”2.0″ />
<pages validateRequest=”false” />
</system.web>
..
</configuration>

Tutorial – Using Oracle Managed Data Access in ASP.NET and C#

1. Install  Oracle.ManagedDataAccess via NuGet package managernuget.PNG

2. Define your data source

Open your Web.config and add to the configuration the following:

<oracle.manageddataaccess.client>
<version number=”*”>
<dataSources>
<dataSource alias=”EXAMPLE” descriptor=”(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=YOUR_HOST_NAME)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=YOUR_SERVICE_NAME)))” />
</dataSources>
</version>
</oracle.manageddataaccess.client>

Here you can read, how to get your HOST_NAME and SERVICE_NAME.

3. Connect to your Oracle

using Oracle.ManagedDataAccess.Client;
using Oracle.ManagedDataAccess.Types;

….

public OracleConnection connectOracle()
{
OracleConnection con = null;
OracleCommand cmd = null;
OracleDataReader reader = null;
try
{
string constr = “user id=YYYYYYY;password=XXXXXXX;data source=EXAMPLE”;
con = new OracleConnection(constr);
con.Open();
cmd = new OracleCommand(“select * from SOMETABLE t”, con);
cmd.CommandType = System.Data.CommandType.Text;

reader = cmd.ExecuteReader();
while (reader.Read())
{
Console.WriteLine(reader.GetString(0)) //Just example
}
}
catch (Exception e)
{
Console.WriteLine(e.StackTrace.ToString());
}
finally
{
if (reader != null && !reader.IsClosed)
reader.Close();
if (con != null && con.State == System.Data.ConnectionState.Open)
con.Close();
con.Dispose();
}
}

Fin.