Category Archives: Clippings

Zato and Pandas (strange combination I know)

I’ve been working with Zato for a project and I’m getting some random text out of a HTTP request that looks like a CSV file, so the easiest way I know how to deal with this CSV data is with Pandas, then I could process it enough and clean it up to hand back to Zato.

But Zato doesn’t ship with Pandas….
(TL;DR at the bottom of the post)

In theory this should work:

/opt/zato/2.0.7/bin/pip install pandas

But then I get the error when I do the following:

/opt/zato/2.0.7/bin/python
>>> import pandas as pd
File "/opt/zato/current/local/lib/python2.7/site-packages/pandas/__init__.py", line 19, in
"Missing required dependencies {0}".format(missing_dependencies))
ImportError: Missing required dependencies ['pytz', 'dateutil']

No luck.

After trying pip install pytz and pip install –upgrade pytz
I get this error:

Installing collected packages: pytz
Found existing installation: pytz 2014.4
Cannot remove entries from nonexistent file /opt/zato/2.0.7/eggs/easy-install.pth

But this does work:

/opt/zato/2.0.7/bin/easy_install --upgrade pytz

Now to fix dateutil.

easy_install --upgrade python-dateutil

Let’s try it again:

/opt/zato/2.0.7/bin/python
>>> import pandas as pd
Traceback (most recent call last):
File "", line 1, in
File "/opt/zato/current/local/lib/python2.7/site-packages/pandas/__init__.py", line 23, in
from pandas.compat.numpy import *
File "/opt/zato/current/local/lib/python2.7/site-packages/pandas/compat/__init__.py", line 361, in
from dateutil import parser as _date_parser
File "/opt/zato/current/local/lib/python2.7/site-packages/python_dateutil-2.6.0-py2.7.egg/dateutil/parser.py", line 40, in
from six import text_type, binary_type, integer_types
ImportError: No module named six

Bummer!


easy_install six

And for a final test:

/opt/zato/2.0.7/bin/python
>>> import pandas as pd
>>>

Yay, it’s working. Hopefully, nothing in Zato has broken…

TL;DR:


/opt/zato/2.0.7/bin/easy_install pandas
/opt/zato/2.0.7/bin/easy_install --upgrade pytz
/opt/zato/2.0.7/bin/easy_install --upgrade pytz
/opt/zato/2.0.7/bin/easy_install six

Yii CGridView Default Order / Yii ActiveRecord Default Sort

Disclaimer, I know next to nothing about Yii….

Today I had an issue with a Yii App and it’s default admin CRUD tables, and sorting fields, well everything that listed a record from the database was in the order it was inserted into the database and not in a human friendly alphabetical order.

It turns out it’s really easy to set a default so that everything that uses the Model, comes out in a sorted way. (Note for larger things, you probably don’t want every single query that hits the DB getting sorted, so you’d probably only apply the sorting as required, but for small things, this shouldn’t be an issue).

For this example I have a Model called ‘Contacts’.

Open up your model (mine is: /models/Contacts.php)

Above the function ‘ public static function model($className=__CLASS__)’

Add the following function (if it’s not present)


/*
* Let's Setup some defaults!
*/
public function defaultScope()
{
return array(
'order' => 'FirstName'
);
}

In the array of ‘order’ change the value to the name of the column that you want to sort by, for my example it was ‘FirstName’.

Save, upload, test, enjoy.

Like I said at the start, I know nothing about Yii, had I, I probably wouldn’t have spent 20 minutes googling it.

Resources: http://www.yiiframework.com/doc/guide/1.1/en/database.ar#default-scope

Windows 10 and iTunes There was an error connecting to the Apple ID server

Recently after a fresh install of Windows 10, I tired to reinstall iTunes.

While trying to authorize my computer for my iPhone Apps I got the following error:

“There was an error connecting to the Apple ID server”

Several reboots later, still no joy. I also noticed that I couldn’t connect to the iTunes store.

I found the following helps?

  1. Right click on the Windows Start Menu Icon and select ‘Command Prompt (Admin)’
  2. Type the following into the command prompt box followed by enter:
    netsh winsock reset
  3. Reboot the computer

How this works: I’m not overly sure why it effects iTunes, but it’s similar to clearing the cache in your browser, just at a network level.

Hopefully this helps someone else.

Reference: https://discussions.apple.com/thread/7192420?start=0&tstart=0

LG-Nortel LDK-300 Phone not allowed to call external numbers

I had a strange phone extension that after lifting the handset, pressing 0 to the get the outside line and dialing the 2nd digit a message on the screen would appear ‘ACCESS DENY’.

It turns out it was a COS issue.

To fix it:

  • Lift the handset and then press ‘TRANS/PGM’
  • Then select option ‘[2] COS / SMS SERVICE’
  • Then select option ‘[2] COS RESTORE’
  • I had ‘ENTER CURRENT PASSWORD’ appear on the screen. How to find that is listed below
  • Enter the password for the station and press the ‘HOLD / SAVE’ button.
  • ‘PROGAM’ Appears on the screen, hang up

To piss off the next person:

  • Lift the handset and then press ‘TRANS/PGM’
  • Then select option ‘[2] COS / SMS SERVICE’
  • Then select option ‘[1] COS DOWN’
  • ‘PROGAM’ Appears on the screen, hang up

How to find out the station password:

In LDK PCADMIN, the ‘Authorization Code Table (PGM227)’ seems to hold all the station passwords. It has 4 columns, Index, Value (this is the password), Day COS, Night COS.
The Index number, appears to line up with the Port number found in the Numbering Plan (PGM104-109).
By comparing the Station number and it’s port number in the Numbering Plan, and using that port number to match up with the index number in Authorization Code Table, I was able to work out the password (sounds complex, but easier when you attempt it).

This system was running the ‘Hotel’ software for the LG-Nortel LDK-300, I would assume that it would be the same in the LDK-130 (if it has a hotel software). I don’t think that the COS features are part of the standard non ‘Hotel’ software. I’m not sure.

Scripting a reboot of a Billion Router over Telnet

Sometimes with older hardware and ADSL connections, you just need to do a reboot every now and then. Newer modems let you do this, but the Billion one I had the joy of playing with today, didn’t.

Lets turn to a simple script running on a Linux box on the same subnet.
Turns out using ‘expect’ you can script a Telnet session. (I know, Telnet isn’t ideal). This could be used across switches, routers, modems, other random boxes that require a telnet interface.

Create a File

nano modem-reboot.sh

Add the code. You’ll need to change the “expect” values as necessary

#!/usr/bin/expect
#If it all goes pear shaped the script will timeout after 20 seconds.
set timeout 20
#First argument is assigned to the variable name
set name [lindex $argv 0]
#Second argument is assigned to the variable user
set user [lindex $argv 1]
#Third argument is assigned to the variable password
set password [lindex $argv 2]
#This spawns the telnet program and connects it to the variable name
spawn telnet $name
#The script expects login
expect "Login:"
#The script sends the user variable
send "$user\r"
#The script expects Password
expect "Password:"
#The script sends the password variable
send "$password\r"
#This hands control of the keyboard over two you (Nice expect feature!)
#interact
#Reboot
expect "admin>"
# Change the following value to whatever your devices reboot command is.
send "system restart\r"

Finally make the file executable


chmod +x modem-reboot.sh

Test it.

Help it doesn’t work.
Under a stock standard Ubuntu 14.04 install I had to add the ‘expect’ package

sudo apt-get install expect

Thanks to http://stackoverflow.com/questions/7013137/automating-telnet-session-using-bash-scripts for the assistance and starting point of the script.

Xero API pyXero and Anaconda Python

Personal TL;DR notes on getting this to work, not a tutorial.

Download Install Anaconda
– At the time of writing it didn’t create Windows Shortcuts, fix this with openning cmd as admin

‘c:\Anaconda2\scripts\conda.exe install menuinst’

Agree to Updates

‘c:\Anaconda2\scripts\conda.exe install -f console_shortcut ipython ipython-notebook ipython-qtconsole launcher spyder’

Agree to updates.

Now there should be shortcuts in:

C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Anaconda2 (64-bit)

Now onto Xero

  • git clone https://github.com/freakboy3742/pyxero.git
  • Open up Anaconda Prompt (Anaconda2x64)
  • cd into folder with git of pyxero
  • use command: python setup.py install
  • pip uninstall oauthlib
  • pip install oauthlib==0.7.2

The last two commands fix the error: ImportError: No module named jwt.algorithms

Again these are personal notes, not a full blown tutorial.

 

Dell Powerconnect 5424 SNMP web management issue

Just ran into a strange issue when configuring a SNMP community on the web interface. Alas it was broken.

2016-01-19 10_36_26-ATKOSD22016-01-19 10_36_26-ATKOSD2

And clicking on “add’ results in an error

‘Access Error: Request Entity Too Large’2016-01-19 10_36_47-ATKOSD2
An easy fix is to stop being lazy and CLI into the switch and fix it.

The command:

snmp-server community public su 192.168.0.5

2016-01-19 10_39_23-Greenshot image editor

And look, it works for us. Now you can webconfig until your heart is content.

2016-01-19 10_38_07-ATKOSD2

Don’t forget to write your switch config changes.

Reference: Dell 5424 CLI Manual, Page 328 ‘snmp-server community’

check_mk_agent over SSH Host key verification failed

Service discovery failed for this host: Agent exited with code 255: Pseudo-terminal will not be allocated because stdin is not a terminal. Host key verification failed.

Current Setup: Ubuntu 14.04 running OMD

Solution: Running the ssh command from the OMD user appears to fix the problem by allowing them into the known hosts list.

Here’s how:

linuxuser@ubuntu_vm:~$ sudo su
[sudo] password for linuxuser:
root@ubuntu_vm:/home/scadmin# su [omd-site-name]
ubuntu_vm[[omd-site-name]]:~$

then run your remote command eg:

ubuntu_vm[[omd-site-name]]:~$ ssh -l root -i /etc/check_mk/check_mk.key [ip]

It will ask to save the host to the known hosts, type yes and enter. It should then output the status from the check_mk agent.