Perl Tail and sendmail

#!/usr/bin/perl
# Butuh libfile-tail-perl
# dibuat oleh : yanto
use File::Tail;
use Mail::Sendmail;

$file=File::Tail->new(name=>”/var/log/messages”,maxinterval=>2, adjustafter=>2);
while (defined($line=$file->read)) {
$needToFind = “DENY:”;
$_ = $line;
# print “$line\n” if m/$needToFind/;

if (m/$needToFind/)
{

%mail = ( To => ‘xxxx@xxxxx.com’,
From => ‘xxxx@xxxxx.com’,
Subject => “vmps : New user”,
Message => “$line”
);

sendmail(%mail) or die $Mail::Sendmail::error;

}
}
exit 0;

Advertisements
By yans008 Posted in Uncategorized

ssh

yanto@local-host$ ssh-keygen
yanto@local-host$ ssh-copy-id -i ~/.ssh/id_rsa.pub remote-host

By yans008 Posted in Uncategorized

Mailman Allow non member pattern

Allow an individual address: apasaja@gmail.com
Allow xxx domain only: ^.*@xxx.com
Allow members from another list to post to your list: @LISTNAME (use only the list name and not the full address; that is, @LISTNAME, not @LISTNAME@xxx.com)
Allow everyone to post: ^.*

By yans008 Posted in Uncategorized

Tutorial Script Mikrotik

:if ( [ / ip dhcp-server lease find ] != “” ) do={ / ip dhcp-server lease remove [ / ip dhcp-server lease find ] };
:if ([len [/file find name=dhcp.rsc]] > 0) do={ /file remove dhcp.rsc}; tool fetch address=www.apasaja.com src-path=/cgi-bin/dhcp.pl dst-path=/dhcp.rsc mode=http;/import dhcp.rsc

/ip dhcp-server export file=([/system identity get name] . “-” . [:pick [/system clock get date] 7 11]. [:pick [/system clock get date] 0 3]. [:pick [/system clock get date] 4 6]);
/tool e-mail send to=”srisuyanto@rekayasa.co.id” subject=([/system identity get name] . ” backup ” . [/system clock get date]) file=([/system identity get name] . “-” . [:pick [/system clock get date] 7 11] . [:pick [/system clock get date] 0 3] . [:pick [/system clock get date] 4 6] . “.rsc”);
/file remove 10

By yans008 Posted in Uncategorized

Automatic Update phpipam hostname and mac address

#!/usr/bin/perl

# Script for update hostname and mac address using nbtscan
# Requirement : perl and nbtscan dbi and net:IPAddress
# By : s.suyanto@gmail.com
# Add to crontab to update periodically
# NEED libnet-address-ip-local-perl
# update-ipam.pl

use DBI;
use Net::IPAddress;
require “/usr/bin/Konfig.pl”;

print “content-type: text/html \n\n”;

#system($dumpipcmd);

# system(“nbtscan -s = 192.168.0.0/16 > /usr/bin/macaddress.txt “);

my $dbh = DBI->connect(“dbi:mysql:$database:$host:3306”, $user, $pw);

$UNIXFILE = “/usr/bin/macaddress.txt”;
open(UNIXFILE) or die(“Could not open UNIX FILE.”);
foreach $line () {
($ip,$nama,$server,$desc,$mac)=split(/\=/ ,$line);
$macaddr = trim(“$mac”);
$ipaddr = trim(“$ip”);
$sysname = trim(“$nama”);
if ( $macaddr !~ ” ” ) {
#printf “$macaddr\n”;
$titik=1;
$baris=””;
@mac = split(/:/, $macaddr);
foreach $macall (@mac) {
if ($titik==2 || $titik==4) {
$baris=”$baris$macall.”;
}
else {
$baris=”$baris$macall”;
}
$titik=$titik+1;
}
$titik=1;
}
$ipnum = ip2num(“$ipaddr”);
printf “$ipnum : $ipaddr : $macaddr : $baris : $sysname \n “;
my $sth = $dbh->prepare(“UPDATE ipaddresses SET dns_name=’$sysname’, mac=’$macaddr’ WHERE ip_addr=’$ipnum'”);
$sth->execute();
}
close(UNIXFILE);
$dbh->disconnect();

================
konfig.pl
===================
#!/usr/bin/perl;

# MYSQL CONFIG VARIABLES 1
$host = “localhost”;
$database = “databasename”;
$user = “username”;
$pw = “password”;

sub trim($)
{
my $string = shift;
$string =~ s/^\s+//;
$string =~ s/\s+$//;
return $string;
}

Quote

Menambahkan otomatis kedalam icinga .

#!/usr/bin/perl
# dijalankan tiap hari berdasarkan crontab daily

use DBI;
require “/etc/icinga/Konfig.pl”;
print “content-type: text/html \n\n”; #The header

my $filename = ‘/etc/icinga/rekind/hosts.cfg’;
open(my $fh, ‘>’, $filename) or die “Could not open file ‘$filename’ $!”;

my $dbh2 = DBI->connect(“dbi:mysql:$database2:$host2:3306”, $user2, $pw2);
my $sth2 = $dbh2->prepare(“SELECT device,devip,serial,location,type,description FROM devices”);
$sth2->execute();

$sth2->bind_columns(undef, \$device, \$devip,\$serial,\$location,\$type,\$description);

while($sth2->fetch()) {

$ipaddr=dec2dot($devip);

print $fh “define host{\n”;
print $fh ” use generic-switch\n”;
print $fh ” host_name $device\n”;
print $fh ” alias $device\n”;
print $fh ” address $ipaddr \n”;
print $fh ” hostgroups all \n”;
print $fh ” }\n”;
print $fh ” \n”;
print $fh ” define service{\n”;
print $fh ” use generic-service \n”;
print $fh ” host_name $device\n”;
print $fh ” service_description PING\n”;
print $fh ” check_command check_ping!200.0,20%!600.0,60%\n”;
print $fh ” check_interval 5 \n”;
print $fh ” retry_interval 1\n”;
print $fh ” }\n”;

}

close (HTML);
$dbh2->disconnect();

Menambahkan otomatis kedalam icinga

Stack Cisco Tips

Tips to Add a Switch as a Slave to the Stack

To add a switch, as a slave, to a stack, complete these steps:

Note: Make sure the switch that you add into the stack has the same IOS version as the switches in the stack. Refer to to upgrade the IOS in a catalyst 3750 switch.

  1. Change the switch priority of the switch to be added to “1”.switch stack-member-number priority new-priority-value Note: This step is optional, but it will make sure that the switch has fewer chances to become a stackmaster in the future.
  2. Power off the switch that is to be added.
  3. Make sure that the stack is fully connected so that, when you connect the new switch, the stack will be at least in half connectivity and does not partition.
  4. Connect the new switch to the stack with the StackWise ports.
  5. Power on the newly added switch.
  6. After the new switch comes up, issue the command show switch to verify stack membership.

 

Source : http://www.cisco.com/c/en/us/support/docs/switches/catalyst-3750-series-switches/71925-cat3750-create-switch-stks.html#anc11

Quote

conf t
ip access-list extended UDP-DDOS
permit udp any any
exit

class-map match-all UDP
match access-group name UDP-DDOS
policy-map 1.0
class UDP
police 1024000 conform-action transmit exceed-action drop
exit
control-plane
service-policy input 1.0
end
wr mem

show policy-map control-plane

Limit UDP On Cisco using policy Map

Port Whatsap

TCP /UDP 4244,5222,5223,5228,5242,5060,5064,59234,50318,8080

UDP : 3478, 45395

By yans008 Posted in Uncategorized

Mikrotik grep dns

# List name
:local LISTNAME “FACEBOOK”
# Check DNS entries and collect matching names
:foreach i in=[/ip dns cache all find where (name ~”facebook.com” || name ~”fbcd.net” || name ~”facebook.net”) && (type=”A”) ] do={
# Get IP Address from the names and hold it in temporary buffer
:local Buffer [/ip dns cache get $i address];
delay delay-time=10ms
# Check if entry is already not exists, then OK, otherwise ignore duplication
:if ( [/ip firewall address-list find where address=$Buffer] = “”) do={
# Fetch DNS names for the entries
:local sitednsname [/ip dns cache get $i name] ;
# Print name in LOG window
:log info (“added entry: $sitednsname $Buffer”);
# Add IP addresses and there names to the address list
/ip firewall address-list add address=$Buffer list=$LISTNAME comment=$sitednsname;
}
}

#YOUTUBE
# List name
:local LISTNAME “YOUTUBE”
# Check DNS entries and collect matching names
:foreach i in=[/ip dns cache all find where (name ~”1e100″ || name ~”twitter” || name ~”instagram” || name ~”.dynect.net” || name ~”video” || name ~”ytimg” || name ~”youtube” || name ~”googlevideo”) && (type=”A”) ] do={
# Get IP Address from the names and hold it in temporary buffer
:local Buffer [/ip dns cache get $i address];
delay delay-time=10ms
# Check if entry is already not exists, then OK, otherwise ignore duplication
:if ( [/ip firewall address-list find where address=$Buffer] = “”) do={
# Fetch DNS names for the entries
:local sitednsname [/ip dns cache get $i name] ;
# Print name in LOG window
:log info (“added entry: $sitednsname $Buffer”);
# Add IP addresses and there names to the address list
/ip firewall address-list add address=$Buffer list=$LISTNAME comment=$sitednsname;
}
}

# List name
:local LISTNAME “LINKED”
# Check DNS entries and collect matching names
:foreach i in=[/ip dns cache all find where (name ~”licdn” || name ~”linkedin”) && (type=”A”) ] do={
# Get IP Address from the names and hold it in temporary buffer
:local Buffer [/ip dns cache get $i address];
delay delay-time=10ms
# Check if entry is already not exists, then OK, otherwise ignore duplication
:if ( [/ip firewall address-list find where address=$Buffer] = “”) do={
# Fetch DNS names for the entries
:local sitednsname [/ip dns cache get $i name] ;
# Print name in LOG window
:log info (“added entry: $sitednsname $Buffer”);
# Add IP addresses and there names to the address list
/ip firewall address-list add address=$Buffer list=$LISTNAME comment=$sitednsname;
}
}