Wednesday, December 31, 2014
java send mail using ubuntu local sendmail smtp
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public static void main(String[] args) {
String to="recipient@example.com";
String from="sender@example.com";
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
// props.put("mail.smtp.host", "localhost"); // optional
String msgBody = "Sending email using JavaMail API...";
try {
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from, "NoReply"));
msg.addRecipient(Message.RecipientType.TO,
new InternetAddress(to, "Mr. Recipient"));
msg.setSubject("Welcome To Java Mail API");
msg.setText(msgBody);
Transport.send(msg);
System.out.println("Email sent successfully...");
} catch (AddressException e) {
throw new RuntimeException(e);
} catch (MessagingException e) {
throw new RuntimeException(e);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public static void main(String[] args) {
String to="recipient@example.com";
String from="sender@example.com";
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
// props.put("mail.smtp.host", "localhost"); // optional
String msgBody = "Sending email using JavaMail API...";
try {
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from, "NoReply"));
msg.addRecipient(Message.RecipientType.TO,
new InternetAddress(to, "Mr. Recipient"));
msg.setSubject("Welcome To Java Mail API");
msg.setText(msgBody);
Transport.send(msg);
System.out.println("Email sent successfully...");
} catch (AddressException e) {
throw new RuntimeException(e);
} catch (MessagingException e) {
throw new RuntimeException(e);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
Wednesday, December 24, 2014
Find largest directories on Linux
sudo du -sh * | sort -nr | head -n10
Thursday, December 18, 2014
Setup Zabbix on Ubuntu for Postgresql connection
1. Install unixODBC >sudo apt-get install unixODBC
2. Install postgresql odbc driver >sudo apt-get install postgresql-odbc
3. Setup /etc/odbc.ini
[test]
Description = 192.168.8.220 test
Driver = postgresql
Servername = 192.168.8.220
Port = 5432
Database = db_name
4. Setup /etc/odbcinst.ini
[postgresql]
Description = ODBC for postgresql
Driver = /usr/lib/x86_64-linux-gnu/odbc/psqlodbca.so
Setup = /usr/lib/x86_64-linux-gnu/odbc/libodbcpsqlS.so
Test:
>isql test your_name your_password -v
In Zabbix, add database monitor:
key = db.odbc.select[some_name,test]
2. Install postgresql odbc driver >sudo apt-get install postgresql-odbc
3. Setup /etc/odbc.ini
[test]
Description = 192.168.8.220 test
Driver = postgresql
Servername = 192.168.8.220
Port = 5432
Database = db_name
4. Setup /etc/odbcinst.ini
[postgresql]
Description = ODBC for postgresql
Driver = /usr/lib/x86_64-linux-gnu/odbc/psqlodbca.so
Setup = /usr/lib/x86_64-linux-gnu/odbc/libodbcpsqlS.so
Test:
>isql test your_name your_password -v
In Zabbix, add database monitor:
key = db.odbc.select[some_name,test]
Postgresql usage notes
Revoke:
REVOKE ALL ON DATABASE db_name FROM user_name;
revoke all on all tables in schema public from zabbix;
Readonly User:
revoke all on schema public from public;
create role zabbix login password 'some_pass';
grant usage on schema public to zabbix;
grant select on public.some_table to zabbix;
REVOKE ALL ON DATABASE db_name FROM user_name;
revoke all on all tables in schema public from zabbix;
Readonly User:
revoke all on schema public from public;
create role zabbix login password 'some_pass';
grant usage on schema public to zabbix;
grant select on public.some_table to zabbix;
When you create a new database, any role is allowed to create objects in the public
schema. To remove this possibility, you may issue immediately after the database creation:
REVOKE ALL ON schema public FROM public;
Edit: after the above command, only a superuser may create new objects inside the public
schema, which is not practical. Assuming a non-superuser foo_user
should be granted this privilege, this should be done with:
GRANT ALL ON schema public TO foo_user;
Friday, December 12, 2014
Configure Zabbix to sent alert email
Setup the host to be monitored

Setup Media Type, in this case, use email and local "sendmail" smtp server. Remember to use 127.0.0.1 on the SMTP server settings. Otherwise, it may have connection problem.

Ensure the User media email is enabled.

Ensure action is enabled.

Set the trigger.


Setup Media Type, in this case, use email and local "sendmail" smtp server. Remember to use 127.0.0.1 on the SMTP server settings. Otherwise, it may have connection problem.

Ensure the User media email is enabled.

Ensure action is enabled.

Set the trigger.

Thursday, December 11, 2014
Connects zabbix server to agent
* Remember to setup the zabbix-agent configuration to listen to the
right server IP and other settings.
log: /var/log/zabbix-agent/zabbix_agentd.log
config: /etc/zabbix/zabbix_agentd.conf
right server IP and other settings.
log: /var/log/zabbix-agent/zabbix_agentd.log
config: /etc/zabbix/zabbix_agentd.conf
ssh-copy-id copy id to remote machine
usage> ssh-copy-id -p 1337 your_name@remote_host
Tuesday, December 9, 2014
Subscribe to:
Posts (Atom)